The installation process is very simple. Simply login to the super user account and type in your root password. Finally install the Z-Shell by typing in the following command.
# pkg install zsh
You will of course need to confirm with a “yes”. The following is the full output of the Z-Shell installation.
# pkg install zsh
Updating FreeBSD repository catalogue...
Fetching data.pkg: 100% 7 MiB 7.2MB/s 00:01
Processing entries: 100%
FreeBSD repository update completed. 34544 packages processed.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
zsh: 5.9_4
Number of packages to be installed: 1
The process will require 20 MiB more space.
5 MiB to be downloaded.
Proceed with this action? [y/N]: yes
[1/1] Fetching zsh-5.9_4.pkg: 100% 5 MiB 5.0MB/s 00:01
Checking integrity... done (0 conflicting)
[1/1] Installing zsh-5.9_4...
[1/1] Extracting zsh-5.9_4: 100%
=====
Message from zsh-5.9_4:
--
==========================================================
By default, zsh looks for system-wide defaults in
/usr/local/etc.
If you previously set up /etc/zprofile, /etc/zshenv, etc.,
either move them to /usr/local/etc or rebuild zsh with the
ETCDIR option enabled.
==========================================================
#
Now that you have it installed, you need to set it up to be used as your shell of choice. I don’t want to set it up as the system-wide default, since I don’t want to change the way FreeBSD works for everyone. Therefore I will only change it for my user account. To do this, I need to create two files in my home folder. The two files are zshrc and zprofile. There are actually 4 configuration files, if you want you can read up on them at freecodecamp. However, we will just use the best practices of using profile to set the environment variables PATH and EDITOR. We will use zshrc for aliases, custom prompts and tweaking the terminal aesthetics.
So to set the shell for your login. You will use the chsh
command. This command is the change shell command. It is one of several commands used to change the user database information.
# chsh -s /usr/local/bin/zsh freebsd
The -
s option sets a new shell for the user freebsd
. The path is the location of the zsh
executable.
The next time you login, the account will start with the z-shell, and will give the following prompt.
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
--- Type one of the keys in parentheses ---
I suggest choosing option (0)
. You then get the following information incase you wish to run the z-shell configuration again.
The function will not be run in future, but you can run
it yourself as follows:
autoload -Uz zsh-newuser-install
zsh-newuser-install -f
The code added to ~/.zshrc is marked by the lines
# Lines configured by zsh-newuser-install
# End of lines configured by zsh-newuser-install
You should not edit anything between these lines if you intend to
run zsh-newuser-install again. You may, however, edit any other part
of the file.
generic%
You can then edit the ~/.zshrc
file to set up your preferences for terminal appearance. You can edit the command prompt to include the user name @ machine name present working director and prompt by entering the following command.
echo "PROMPT='%n@%m %1~ %# '" >> ~/.zshrc
You can then reload your prompt by reloading the zshrc file.
source ~!/.zshrc
Your prompt will now appear like this and you are ready to use the Z-shell.
freebsd@RPI3B ~ %