Install Zsh and Oh My Zsh on Linux from Command Line: Best 5 Steps

Posted on

Install Zsh and Oh My Zsh on Linux from Command Line: Best 5 Steps

Install Zsh and Oh My Zsh on Linux from Command Line: Best 5 Steps

This tutorial intends to teach you to Install Zsh and Oh My Zsh on Linux from 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. Follow the guide steps provided by the Orcacore team to Install Zsh and Oh My Zsh on Linux from 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. To Install Zsh and Oh My Zsh on Linux from Command Line, follow the steps below.

Step 1 – 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

In this step of Install Zsh and Oh My Zsh on Linux from Command Line, 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
Install Zsh and Oh My Zsh on Linux from Command Line

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

In this step of Install Zsh and Oh My Zsh on Linux from Command Line, 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 on Linux from 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 this guide on Install Zsh and Oh My Zsh on Linux from Command Line. You may be interested in these articles:

12 Commands to Check Linux System and Hardware Information

Install Sublime Text on Ubuntu 22.04

Alternative Solutions for Installing and Configuring Zsh

While the provided method effectively installs Zsh and Oh My Zsh, alternative approaches exist that offer different benefits. Here are two different ways to achieve a similar outcome:

1. Using a Package Manager with a GUI (Graphical User Interface):

While the original article focuses on command-line installation, many Linux distributions offer graphical package managers like Synaptic (Debian-based) or GNOME Software (most distributions). This approach can be more intuitive for users less comfortable with the command line.

Explanation:

GUI package managers provide a visual interface for browsing, searching, and installing software packages. They abstract away the command-line syntax of apt or dnf, making the process more accessible.

Steps:

  1. Open the Package Manager: Locate and open your distribution’s package manager (e.g., Synaptic, GNOME Software, KDE Discover).
  2. Search for Zsh: Use the search function to find the zsh package.
  3. Mark for Installation: Select the zsh package and mark it for installation. The package manager will typically resolve any dependencies automatically.
  4. Apply Changes: Click the "Apply" or "Install" button to begin the installation process. You may be prompted for your administrator password.
  5. Install Oh My Zsh: After Zsh is installed, open a terminal and follow the steps in the original article to install Oh My Zsh via the command line:
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  6. Set Zsh as Default (Using GUI or Command Line): Some distributions allow setting the default shell through the GUI system settings (search for "default shell" in your system settings). Alternatively, you can use the chsh command as described in the original article.

Advantages:

  • More user-friendly for beginners.
  • Visual feedback on the installation process.
  • Automatic dependency resolution.

Disadvantages:

  • May be slower than command-line installation.
  • Requires a graphical environment.
  • Oh My Zsh installation and customization still require the command line.

2. Using a Dotfile Manager (e.g., chezmoi, dotdrop, yadm):

This method focuses on managing the configuration files (dotfiles) for Zsh and Oh My Zsh in a more organized and reproducible way, which is particularly useful for managing your shell configuration across multiple machines or for sharing your setup.

Explanation:

Dotfile managers are tools that help you track, version control, and deploy your configuration files. They allow you to store your .zshrc and other configuration files in a Git repository and easily apply them to new systems. This is a more advanced approach but offers significant benefits in terms of configuration management.

Steps (using chezmoi as an example):

  1. Install chezmoi: Follow the installation instructions for your distribution from the chezmoi website (usually involves downloading a binary or using a package manager).
  2. Initialize chezmoi:
    chezmoi init
  3. Add Existing Configuration (if any): If you already have a .zshrc file, add it to chezmoi:
    chezmoi add ~/.zshrc
  4. Edit the Configuration: chezmoi will create a template version of your .zshrc file in its source directory. Edit this template to configure your Zsh and Oh My Zsh settings. You can use chezmoi edit ~/.zshrc to open the file in your default editor.
  5. Apply the Configuration: Apply the configuration to your system:
    chezmoi apply
  6. Version Control: Commit your changes to the Git repository managed by chezmoi.

Example .zshrc.tmpl (chezmoi template):

# ~/.zshrc.tmpl
export ZSH="$HOME/.oh-my-zsh"

# Set theme
ZSH_THEME="{{ .theme }}"  # Example using a variable

# Set up plugins
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

source $ZSH/oh-my-zsh.sh

# Example alias
alias ga='git add'

# Source custom scripts (if any)
if [[ -f ~/.zshrc.local ]]; then
  source ~/.zshrc.local
fi

In this example, {{ .theme }} is a template variable that can be set in chezmoi‘s configuration file.

  1. Deploy to New Machines: On a new machine, install chezmoi, initialize it from your Git repository, and run chezmoi apply to automatically configure Zsh and Oh My Zsh.

Advantages:

  • Centralized configuration management.
  • Version control of your shell configuration.
  • Easy deployment of your configuration to multiple machines.
  • Reproducible environment.

Disadvantages:

  • More complex setup.
  • Requires familiarity with Git and templating.
  • Overkill for single-machine setups with minimal customization.

These alternative methods offer different approaches to installing and configuring Zsh, catering to varying levels of technical expertise and configuration management needs. Choose the method that best suits your individual requirements and preferences.

Leave a Reply

Your email address will not be published. Required fields are marked *