Install Zsh and Oh My Zsh on Linux from Command Line

This tutorial intends to teach you to Install Zsh and Oh My Zsh Framework on Linux distributions from the Command Line. Zsh or Z Shell is the most popular shell for Linux operating systems. It is highly customizable and supports many plugins. Also, it offers many new features to the Linux users.

Steps To Install Zsh on Linux from the Command Line

You can follow this guide, to install Zsh on Debian-based and RHEL-based distros and set it as the default shell on Linux. Also, you will learn to install the Oh My Zsh framework to install and maintain zsh plugins, and themes, make new shell aliases, and more. 

Step1 – Install Zsh on Debian / Ubuntu

The Zsh packages are available in the default Debian-based repositories. Here to show you the example setup, we use Ubuntu 22.04.

First, run the system update with the command below:

sudo apt update

Then, install Zsh on Debian and Ubuntu with the following command:

sudo apt install zsh -y

Verify your Zsh installation by checking its version:

zsh --version
Output
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

Step 2 – Install Zsh on Centos / AlmaLinux / Rocky Linux / RHEL

Also, the Zsh packages are available in the default RHEL-based distros. Here as an example, we use AlmaLinux. First, run the system update with the command below:

sudo dnf update -y

Then, install Zsh on RHEL-based distros with the following command:

sudo dnf install zsh -y

Verify your installation by checking the Zsh version:

zsh --version
Output
zsh 5.8 (x86_64-redhat-linux-gnu)

Step 3 – Switch To Zsh in Linux – Set Zsh as the Default Shell

At this point, you can easily switch to the Zsh on your Linux distro and set it as your default shell. To do this, follow the steps below.

First, check your current shell with the command below:

sudo echo $SHELL
Output
/bin/bash

Then, find your Zsh path on your system with the command below:

sudo which zsh
Output
/usr/bin/zsh

Next, to set your Zsh as the default shell, you can use the following command with the path of Zsh:

sudo chsh -s /usr/bin/zsh

If you don’t know the exact path, you can use the following command instead:

sudo chsh -s $(which zsh)
Output
Changing shell for root.
Shell changed.

Step 4 – Install Oh My Zsh Framework on Linux

Oh my Zsh is a framework for Z shell that is used to install and maintain zsh plugins, and themes, make new shell aliases, and more. It includes a set of pre-configured settings and functions to make customizations easy for users of every type. 

Note: Remember to install Git on your server first.

$ sudo apt install git #For Debian-Based 
$ sudo dnf install git #For RHEL-based

To install Oh My Zsh, you can run the following command on your Linux server:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

When your installation is completed, you will see:

Oh My Zsh Screen on Linux

As we said, Oh My Zsh has pre-configured settings. For example, to list pre-installed themes, you can use the command below:

ls ~/.oh-my-zsh/themes/
Output
3den.zsh-theme             kiwi.zsh-theme
adben.zsh-theme            kolo.zsh-theme
af-magic.zsh-theme         kphoen.zsh-theme
afowler.zsh-theme          lambda.zsh-theme
agnoster.zsh-theme         linuxonly.zsh-theme
alanpeabody.zsh-theme      lukerandall.zsh-theme
amuse.zsh-theme            macovsky-ruby.zsh-theme
apple.zsh-theme            macovsky.zsh-theme
arrow.zsh-theme            maran.zsh-theme
...
➜  ~

Then, if you want to apply your desired theme, you need to configure it in the .zshrc config file. You can edit the file with your favorite text editor, We use the vi editor:

vi .zshrc

Find the following line in the file:

ZSH_THEME="robbyrussell"

And to change the theme, change the value to your desired one. For example:

ZSH_THEME="agnoster"

When you are done, save and close the file.

To apply the changes, source the .zshrc file with the command below:

source ~/.zshrc

Also, you can exit from Oh My Zsh, by typing exit:

exit

Step 5 – Switch Back From Zsh To Bash on Linux

If you plan to switch to your Bash shell, you can easily use the following command:

chsh -s $(which bash)

Then, log out from your shell log in again, and check your current shell:

 echo $SHELL
Output
/usr/bin/bash

Step 6 – Uninstall Zsh From Linux

At this point, if you no longer want to use Zsh on your Linux server, you can easily remove it with the following commands:

$ sudo apt --purge remove zsh #Debian-Based Distros
$ sudo dnf --remove zsh #RHEL-Based Distros

Conclusion

At this point, you have learned to Install Zsh and Oh My Zsh Framework on Linux from the Command Line. The Zsh packages are available in the Linux repositories, you can easily install it on your server. Oh My Zsh is a framework that you can download and install to your server and use to install and maintain Zsh plugins, themes, etc.

Hope you enjoy it. You may be interested in these articles:

12 Commands to Check Linux System and Hardware Information

Install Sublime Text on Ubuntu 22.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!