What is Zsh? Short for Z shell, Zsh is command line shell with a lot of new features and supports themes and plugins. Zsh is based on bash and therefore it is quite easy to switch between the two command lines. Bash is the default shell in Linux systems and Zsh is an improvement of Bash. We are going to look at how to install and use Zsh and Oh My Zsh on Linux Mint 20.
What are the Major features of Zsh?
Looking at the features of Zsh would help answer the question, ‘why use Zsh?’. Being an improvement of Bash, Zsh share command with Bash but it also comes with quite a number of additional features that makes it easy and interesting to use shell. To list a few major ones, here are they:
- Automatic cd: to change to a new directory, you just have to type the name of the directory
- Spelling correction: Zsh fixes spelling mistakes made when typing a name of a directory
- Recursive path expansion: for instance “/u/lo/b” expands to “/usr/local/bin”
- Support for themes and plugin: Zsh includes various plugin frameworks
Now that we know what Zsh is, the other question we should be asking ourselves is ‘what is oh my Zsh?’ Oh my Zsh is an open-source and community driven framework that manages Zsh configuration. It features a good number of functions, themes, plugins and helpers that make use of shell more interesting.
Step 1: Update your system and Install tools needed to set up Zsh and Oh My Zsh
For the installation of Zsh and Oh My Zsh, we need a number of tools which can be installed using the below command.
sudo apt-get update sudo apt install wget curl git -y
Step 2: Install Zsh on Linux Mint 20
Zsh is already available in Linux Mint 20 repository making it easy to install. Run the command below
sudo apt-get install zsh -y
Check the installed version to confirm Zsh installation
$ zsh –version
Step 3: Switch to Zsh shell on Linux Mint 20
Once installed, change the default shell of root user to zsh by running the below command
sudo chsh -s /usr/bin/zsh $USER
Now log out from the current shell then log back in. When you switch to root user, you will notice that the shell has changed. To verify which shell you are currently in, run the below command:
$ echo $SHELL
Step 4: Install Oh-My-Zsh on Linux Mint 20
As explained before, Oh-My-Zsh is used to manage Z shell and it provides quite a number of functions,themes and plugins. To install Oh-My-Zsh, we first need to install some packages that will enable us to download Oh-My-Zsh installer script.
sudo apt-get install wget git
Now down and execute Oh-My-Zsh installer script
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
The output should be as below:
Step 5: Create a configuration file for Zsh
Just as Bash has .bashrc configuration file, Zsh also needs to have a configuration file called .zshrc which is found in the Oh-My-Zsh template directory if not already on your home directory. To enable the configuration file, run the below commands, first one if .zshrc is not on your home directory or jump to the second command if you have .zshrc in your home directory
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc source ~/.zshrc
At this point, Oh-My-Zsh has been installed successfully and Zsh configured to use Oh-My-Zsh framework having default configurations.
Step 6: Change Zsh default themes
The current default theme provided by Oh-My-Zsh is ‘robbyrusell‘ theme. To check the available themes, change to the theme directory and list its content as shown below.
cd ~/.oh-my-zsh/themes/ ls -a
Among other themes are the ones shown below:
To change default theme, edit the .zshrc configuration file as shown below. Open with your favorite editor
$ vim ~/.zshrc
Look out for the ZSH_THEME parameterand input a theme of your choice. For example, in my case, I am changing to ‘risto’ theme so thst my file will have a line as shown:
Now you need to reload the configuration file with the source command for the new changes to be effected.
$ source ~/.zshrc
Step 7: Enable Oh-My-Zsh Plugins
Oh-My-Zsh provides various plugins that favor different individuals such as developers, system admins and the normal shell users. Check the available plugins by running the command below:
cd ~/.oh-my-zsh/plugins/ ls -a
Some of the available plugins are as shown below:
Different plugins are enabled by editing .zshrc configuration file. Open .zshrc with your favorite editor and look for plugins=() parameter. You can enable many plugins within the brackets as you need. Below is an example:
$ vim ~/.zshrc plugins=(git extract web-search yum git-extras docker vagrant)
Enjoy your Z shell and check below video courses to help you master Linux terminal.
Click on the links below for more Linux guides