Install Zsh on Ubuntu 24.04

|
Last Updated:
|
|

In this tutorial, we are going to learn how to install Zsh on Ubuntu 24.04. Zsh is a versatile UNIX shell with interactive login and script processing capabilities, closely resembling ksh but offering numerous enhancements, including command-line editing, built-in spelling correction, programmable command completion, shell functions with autoloading, a history mechanism, and various other features.

Installing Zsh on Ubuntu 24.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.

Install ZSH

In order to install Zsh, there are a few tools we will need. These include wget, curl and git. They can be installed by running the command below;

sudo apt update
sudo apt install wget curl git -y

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

sudo apt install zsh

To check installed version of ZSH;

Command output

zsh 5.9 (x86_64-ubuntu-linux-gnu)

Configure ZSH on Ubuntu 24.04

You can begin by changing your default shell to zsh. Replace kifarunix with your username.

sudo usermod -s $(which zsh) kifarunix

If you are logged in on a shell as 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;

echo $SHELL

Command output;

/usr/bin/zsh

Install Oh-my-Zsh on Ubuntu 24.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 24.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/.

ls -1 $HOME/.oh-my-zsh/themes/
3den.zsh-theme
adben.zsh-theme
af-magic.zsh-theme
afowler.zsh-theme
agnoster.zsh-theme
alanpeabody.zsh-theme
amuse.zsh-theme
apple.zsh-theme
arrow.zsh-theme
aussiegeek.zsh-theme
avit.zsh-theme
awesomepanda.zsh-theme
bira.zsh-theme
blinks.zsh-theme
bureau.zsh-theme
candy-kingdom.zsh-theme
candy.zsh-theme
clean.zsh-theme
cloud.zsh-theme
crcandy.zsh-theme
crunch.zsh-theme
cypher.zsh-theme
dallas.zsh-theme
darkblood.zsh-theme
daveverwer.zsh-theme
dieter.zsh-theme
dogenpunk.zsh-theme
dpoggi.zsh-theme
dstufft.zsh-theme
dst.zsh-theme
duellj.zsh-theme
eastwood.zsh-theme
edvardm.zsh-theme
emotty.zsh-theme
essembeh.zsh-theme
evan.zsh-theme
fino-time.zsh-theme
fino.zsh-theme
fishy.zsh-theme
flazz.zsh-theme
fletcherm.zsh-theme
fox.zsh-theme
frisk.zsh-theme
frontcube.zsh-theme
funky.zsh-theme
fwalch.zsh-theme
gallifrey.zsh-theme
gallois.zsh-theme
garyblessington.zsh-theme
gentoo.zsh-theme
geoffgarside.zsh-theme
gianu.zsh-theme
gnzh.zsh-theme
gozilla.zsh-theme
half-life.zsh-theme
humza.zsh-theme
imajes.zsh-theme
intheloop.zsh-theme
itchy.zsh-theme
jaischeema.zsh-theme
jbergantine.zsh-theme
jispwoso.zsh-theme
jnrowe.zsh-theme
jonathan.zsh-theme
josh.zsh-theme
jreese.zsh-theme
jtriley.zsh-theme
juanghurtado.zsh-theme
junkfood.zsh-theme
kafeitu.zsh-theme
kardan.zsh-theme
kennethreitz.zsh-theme
kiwi.zsh-theme
kolo.zsh-theme
kphoen.zsh-theme
lambda.zsh-theme
linuxonly.zsh-theme
lukerandall.zsh-theme
macovsky-ruby.zsh-theme
macovsky.zsh-theme
maran.zsh-theme
mgutz.zsh-theme
mh.zsh-theme
michelebologna.zsh-theme
mikeh.zsh-theme
miloshadzic.zsh-theme
minimal.zsh-theme
mira.zsh-theme
mlh.zsh-theme
mortalscumbag.zsh-theme
mrtazz.zsh-theme
murilasso.zsh-theme
muse.zsh-theme
nanotech.zsh-theme
nebirhos.zsh-theme
nicoulaj.zsh-theme
norm.zsh-theme
obraun.zsh-theme
oldgallois.zsh-theme
peepcode.zsh-theme
philips.zsh-theme
pmcgee.zsh-theme
pygmalion-virtualenv.zsh-theme
pygmalion.zsh-theme
random.zsh-theme
re5et.zsh-theme
refined.zsh-theme
rgm.zsh-theme
risto.zsh-theme
rixius.zsh-theme
rkj-repos.zsh-theme
rkj.zsh-theme
robbyrussell.zsh-theme
sammy.zsh-theme
simonoff.zsh-theme
simple.zsh-theme
skaro.zsh-theme
smt.zsh-theme
Soliah.zsh-theme
sonicradish.zsh-theme
sorin.zsh-theme
sporty_256.zsh-theme
steeef.zsh-theme
strug.zsh-theme
sunaku.zsh-theme
sunrise.zsh-theme
superjarin.zsh-theme
suvash.zsh-theme
takashiyoshida.zsh-theme
terminalparty.zsh-theme
theunraveler.zsh-theme
tjkirch_mod.zsh-theme
tjkirch.zsh-theme
tonotdo.zsh-theme
trapd00r.zsh-theme
wedisagree.zsh-theme
wezm+.zsh-theme
wezm.zsh-theme
wuffers.zsh-theme
xiong-chiamiov-plus.zsh-theme
xiong-chiamiov.zsh-theme
ys.zsh-theme
zhann.zsh-theme

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.

Before you can change to a theme, you can preview them here.

For example, to change the theme to gnzh theme, $HOME/.oh-my-zsh/themes/gnzh.zsh-theme, update the ZSH_THEME line so it look like;

ZSH_THEME="gnzh"

Save and exit the file.

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

source ~/.zshrc

This is how gnzh theme looks like;

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" )

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

Command output;

$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 install the fonts, create a .fonts directory in your home directory if it doesn’t already exist:

[ -d ~/.fonts ] || mkdir ~/.fonts

Copy all the downloaded fonts to the fonts directory created above.

cp ~/Downloads/*.ttf ~/.fonts/

Refresh the font cache for your user:

fc-cache -f -v ~/.fonts

Now, the TrueType font should be available for use by applications for your user only

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, close the Preferences window.

For some terminals, you have to close them and open them again to be able to see the fonts.

Once that is done, 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. Choose how you want your shell 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 24.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.

zsh plugins

There are a lot of customization 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 Zsh on Ubuntu.

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment