Getting started with Oh My Zsh
Z Shell, or ZSH for short, is a Unix (including GNU/Linux and macOS) command line interpreter developed by Paul Falstad in 1990. ZSH can be called an extended version of the Bourne Again Shell (BASH) because it has similar features.
ZSH has become one of the popular shells for Unix systems due to its features, flexibility and customizability. The most important features are:
- Automatic command correction
- Command autocomplete
- Improved shell variable handling
- Easy setup and shell customization
Oh-My-Zsh is the most popular plugin framework for zsh (Z Shell). It has many built-in plugins and themes.
This guide will provide information on installing and configuring the ZSH shell and oh-my-zsh framework on Linux.
How to Install Oh My Zsh and ZSH?
Many Linux distributions have ZSH in their package repositories.
Step-1: Install ZSH
You can install ZSH on some distributions as follows:
sudo apt install zsh -y # For Debian Based OS(Ubuntu, Mint, Pardus etc) sudo apt-get install zsh -y # For Debian-based old version operating systems (Ubuntu, Mint, Pardus etc.) sudo pacman -S zsh # For Arch Linux sudo dnf install zsh # For Redhat-based OS(Centos, Fedora, AlmaLinux, Rocky Linux etc) sudo yum install zsh -y # For Redhat-based old version operating systems(Centos, Fedora, AlmaLinux, Rocky Linux etc) sudo zypper install zsh # For openSUSE
You can ignore these steps if ZSH is already installed.
Step-2: Change default shell with ZSH
Now set ZSH as the default shell for the user. Default SHELL is bash on many systems:
cat /etc/passwd
The default shell for the user (foc
user in the example) is set to zsh with the following command:
[foc@rocky9 ~]$ sudo usermod -s $(which zsh) foc
Log out of the user session and login again. Then you will see the following screen:
This is the Z Shell configuration function for new users, zsh-newuser-install. You are seeing this message because you have no zsh startup files (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory ~). This function can help you with a few settings that should make your use of the shell easier. You can: (q) Quit and do nothing. The function will be run again next time. (0) Exit, creating the file ~/.zshrc containing just a comment. That will prevent this function being run again. (1) Continue to the main menu. --- Type one of the keys in parentheses --- 0 [foc@rocky9]~%
We entered the value 0, we chose to create a new .zshrc
file. Default shell for user:
[foc@rocky9]~% echo $SHELL
/usr/bin/zsh
[foc@rocky9]~% cat /etc/passwd | grep foc
foc:x:1000:1000:foc:/home/foc:/usr/bin/zsh
Created .zshrc file in user home directory:
[foc@rocky9]~% ls -la .zshrc
-rw-r--r--. 1 foc foc 29 Oct 31 16:32 .zshrc
Step-3: Install oh-my-zsh
We will pull the install.sh file using cURL or wget. One of these packages (we will continue using wget) must be installed on the system. You also need to have the git package installed.
sudo apt install git wget -y # For Debian Based OS(Ubuntu, Mint, Pardus etc) sudo apt-get install git wget -y # For Debian-based old version operating systems (Ubuntu, Mint, Pardus etc.) sudo pacman -S git wget # For Arch Linux sudo dnf install git wget # For Redhat-based OS(Centos, Fedora, AlmaLinux, Rocky Linux etc) sudo yum install git wget -y # For Redhat-based old version operating systems(Centos, Fedora, AlmaLinux, Rocky Linux etc) sudo zypper install git wget # For openSUSE
For cURL, simply type curl instead of wget in the above setup commands. Then install the script:
Install oh-my-zsh via wget:
[foc@rocky9]~% sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
Install oh-my-zsh via curl:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
We continue with wget:
[foc@rocky9]~% sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" --2022-10-31 22:22:13-- https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh Resolving raw.github.com (raw.github.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ... Connecting to raw.github.com (raw.github.com)|185.199.110.133|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh [following] --2022-10-31 22:22:14-- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.110.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected. ... Already on 'master' /home/foc ...
Installation is complete.
Step-3: Change oh-my-zsh themes
Oh-my-zsh themes are in the following directory:
➜ ~ ls -la .oh-my-zsh/themes
total 592
drwxr-xr-x. 2 foc foc 8192 Oct 31 22:22 .
drwxr-xr-x. 12 foc foc 4096 Oct 31 22:22 ..
-rw-r--r--. 1 foc foc 325 Oct 31 22:22 3den.zsh-theme
-rw-r--r--. 1 foc foc 4017 Oct 31 22:22 adben.zsh-theme
-rw-r--r--. 1 foc foc 1525 Oct 31 22:22 af-magic.zsh-theme
-rw-r--r--. 1 foc foc 444 Oct 31 22:22 afowler.zsh-theme
...
To change the theme, open .zshrc with the vi text editor, write the new theme instead of the old theme and exit:
➜ ~ vi .zshrc
#ZSH_THEME="robbyrussell"
ZSH_THEME="kiwi"
┌[kiwish-4.2]-(~)- └>
Summary
You can review the oh-my-zsh themes without installing them. If you want to use a theme other than the default themes, simply download the theme to the themes directory and define it in the .zshrc
file.
In this article, we explained the installation and configuration of ZSH and oh-my-zsh. You can visit the wiki page for more information.
References
ohmyz.sh - Install oh-my-zsh now