Install and Setup ZSH and Oh-My-Zsh on Ubuntu 20.04

0
738

In this tutorial, we are going to learn how to install and setup Zsh and Oh-my-Zsh on Ubuntu 20.04.

Z shell (ZSH) Zsh is a UNIX command interpreter (shell) usable as an interactive login shell and as a shell script command processor. It incorporates features of other shells such as Bash, tcsk, ksh. Some of the features include;

  • Smart command TAB auto-completion
  • Improved variable/array handling
  • Spelling correction
  • Enables sharing of command history among all running shells
  • Editing of multi-line commands in a single buffer
  • It is highly customization

Zsh configuration is managed by a delightful, open source and community-driven framework called Oh My Zsh. Oh My Zsh comes bundled with a ton of functions, helpers, plugins and themes that can be used to spice your shell experience.

Want to install Ubuntu 20.04 on VirtualBox? Follow the link below to setup one.

Install Ubuntu 20.04 on VirtualBox

Install and Setup ZSH and Oh-My-Zsh on Ubuntu 20.04

In order to install and setup ZSH and Oh-My-Zsh on Ubuntu 20.04, there are a few tools we will need. These include wget, curl and git. They can be installed by running the command below;

apt install wget curl git -y

Instal ZSH on Ubuntu 20.04

ZSH is available on the default Ubuntu 20.04 default repos. Thus to install it and its required dependencies, run the command;

apt install zsh

To check installed version of ZSH;

zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)

Configure ZSH on Ubuntu 20.04

You can begin by changing your default shell to zsh.

usermod -s $(which zsh) koromicha

If you are logged in on a shell you are on a standard user, simply change your shell by running;

chsh -s $(which zsh)

If you do not have enough privileges to run chsh or usermod command, simply check suggestions listed here or here on how to change shell as non-privileged user. Not sure it’s gonna work.

Close the current terminal and open a new one to use your new shell. If this doesn’t work, simply logout and re-login. Once logged in, open a terminal. You will be prompted to set your Zsh start up files. See the screenshot below;

To populate your ~/.zshrc with the default configuration settings, select option 2. You will immediately see changes on the appearance of your shell prompts.

To confirm the current shell;

[email protected] ~ % echo $SHELL
/usr/bin/zsh

Install Oh-my-Zsh on Ubuntu 20.04

To be able to customize the appearance of your ZSH, you need the oh-my-zsh framework which can be installed by either using the curl or wget commands as shown below;

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

or

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

Upon installation, you will see yet another change in the appearance of your terminal.

Configure Oh-My-Zsh on Ubuntu 20.04

Want the “oh-my-zsh” feeling, right? Proceed to configure it. The Oh-my-Zsh configuration files are located under $HOME/.oh-my-zsh/ directory. Note that ZSH config file is $HOME/.zshrc.

Oh-My-Zsh Theme Configuration

Oh-My-Zsh themes are located under $HOME/.oh-my-zsh/themes/. To change the ZSH theme, open the configuration file, $HOME/.zshrc, and set the value of ZSH_THEME= to the name of your preferred theme.

vim $HOME/.zshrc

robbyrussel is the default theme for ZSH.

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
...

To change the theme, simply get the name of the theme from $HOME/.oh-my-zsh/themes/ and replace robbyrussell with it. For example, to change the themes to gnzh theme, $HOME/.oh-my-zsh/themes/gnzh.zsh-theme,

ZSH_THEME="gnzh"

Reload the ~/.zshrc to effect the changes everytime you make changes.

source ~/.zshrc

This is how gnzh theme looks like;

Install and Setup ZSH and Oh-My-Zsh on Ubuntu 20.04

Want to use multiple selected themes randomly? Edit the $HOME/.zshrc and set the theme to random.

ZSH_THEME="random"

Then, define the themes to use in a random manner as in;

ZSH_THEME_RANDOM_CANDIDATES=( "gnzh" "agnoster" "robbyrussel" )

Check more themes on ohmyzsh themes Github repository.

Oh-My-ZSH Custom Themes

There are also other external ohmyzsh themes that you can check on. Custom themes can be installed on $ZSH_CUSTOM directory.

echo $ZSH_CUSTOM
$HOME/.oh-my-zsh/custom

For example, let us try Powerlevel10k.

Install Powerlevel10k Oh-My-Zsh Theme

To install and use Powerlevel10k theme, you first need to install the recommended font, Meslo Nerd Font patched for Powerlevel10k.

Download Meslo Nerd Font patched for Powerlevel10k fonts;

cd $HOME/Downloads
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf

To instal the fonts, navigate to the downloads directory and double click and install each one of them so as to make MesloLGS NF font available system wide.

Next, configure your terminal to use Powerlevel10k MesloLGS NF font. Each type of terminal has a different way in which it can be configured to use this theme.

For example, to configure GNOME terminal to use this font;

  • Right click anywhere on the terminal and select Preferences.
  • On the selected profile, under Profiles, check Custom font under Text Appearance and select MesloLGS NF Regular.
  • Once you set the theme, click the Preferences window.

Download and Install Powerlevel10k Oh-My-Zsh Theme

You can then download and install Powerlevel10k oh-my-zsh theme by running the command below;

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

Once Powerlevel10k theme is in place, edit the Zsh configuration file, $HOME/.zshrc, and change the theme to powerlevel10k/powerlevel10k.

vim $HOME/.zshrc
...
# ZSH_THEME="robbyrussell"
# ZSH_THEME="gnzh"
ZSH_THEME="powerlevel10k/powerlevel10k"

Save and exit the Zsh configuration then reload the configs.

source ~/.zshrc

Upon reloading Zsh configs, Powerlevel10k configuration wizard will ask a few questions so as to configure your prompt. Answer the questions appropriately.

Select your shell promt.

Configure how you want your prompt to look like by going through a series of provided questions.

Once, done save the changes and your Powerlevel10k prompt now looks like;

oh my zsh!!! Isn’t it?

Enable Oh-My-Zsh Plugins on Ubuntu 20.04

There are a ton of oh-my-zsh plugins to further spice up your shell. Plugins are stored under,  ~/.oh-my-zsh/plugins. It is also possible to define custom plugin location, like, ~/.oh-my-zsh/custom/plugins

Plugins can be enabled by defining them under the plugins section on ~/.zshrc config file. For example, to enable colored man pages plugin;

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git colored-man-pages)

Save and exit the shell. Then source ~/.zshrc for the changes to take effect.

source ~/.zshrc

The verify the plugin by running, man man.

There are a lot of customizations that can be done on ZSH and Oh-My-Zsh. Feel free to explore. Otherwise, we have come to an end of our guide on how to install and setup ZSH and Oh-My-Zsh on Ubuntu 20.04.

See Also;

How to Install AnyDesk on Ubuntu 20.04

Upgrade Ubuntu 18.04 to Ubuntu 20.04

Install VirtualBox Guest Additions on Ubuntu 20.04

How to Install and Setup ZSH and Oh-My-Zsh on Ubuntu 18.04

LEAVE A REPLY

Please enter your comment!
Please enter your name here