Mohan pd.
Mohan pd. Author of The Coders Blog. Also a professional fullstack javascript developer working with various tech company and client around world.

Installing ZSH & Oh-my-zsh on Linux

Nov 06, 2019 · 4 minutes
Installing ZSH &  Oh-my-zsh on Linux

ZSH is one of the most powerful interactive UNIX shell Zsh was developed by ‘Paul Fastad’ since 1990, and the name ‘zsh’ comes from the Yale professor Zong Shao.

How to install zsh on many platforms

macOS

Try zsh --version before installing it from Homebrew. If it’s newer than 4.3.9 you might be OK. Preferably newer than or equal to 5.0.

brew install zsh zsh-completions

To set zsh as your default shell, execute the following for macOS High Sierra

chsh -s /bin/zsh

Assuming you have Homebrew installed. If not, most versions of macOS ship zsh by default, but it’s normally an older version. Alternatively, you may also use MacPorts

sudo port install zsh zsh-completions

Ubuntu, Debian & derivatives (Windows 10 WSL | Native Linux kernel with Windows 10 build 1903)

apt install zsh

If you don’t have apt, the recommended package manager for end users [1] [2] [3] [4] , you can try apt-get or aptitude.

Other distributions that apply include: Linux Mint, elementary OS, Zorin OS, Raspbian, MX Linux, Deepin.

OpenSUSE

zypper install zsh

Arch Linux

pacman -S zsh

Void Linux

xbps-install zsh

Fedora

dnf install zsh

OpenBSD

To install the package:

pkg_add zsh

FreeBSD

To install the package:

pkg install zsh

To install the port:

cd /usr/ports/shells/zsh/ && make install clean

To reduce memory usage, optionally enable zsh-mem options with

make config

before running “make install”.

Centos/RHEL

sudo yum update && sudo yum -y install zsh

Cygwin

Install the zsh package using the installer. Unfortunately Cygwin doesn’t have a standard command line interface.

The easiest way to change the default shell is to set your SHELL user environment variable. Search for “Edit Environment variables for your account” to bring up the environment variables window, create a new variable named “SHELL” and give it the value “/usr/bin/zsh/”.

Alternatively: Open Cygwin (in BASH) then type:

sudo nano ~/.bashrc

Once the .bashrc file is open, add this line to the very top:

exec zsh

Close and save the file. Close and reopen Cygwin. It will execute the command every time you load the terminal and run your zsh shell.

Solus

eopkg it zsh

Funtoo/Gentoo

emerge app-shells/zsh

Alpine Linux

apk add zsh

MSYS2

pacman -S zsh

Termux (Android)

Termux is an terminal emulator for Android but has modern feature like Debian and Ubuntu (Termux has Bash shell and Busybox GNU-like programs). For the package manager, Termux using an Debian/Ubuntu package manager, APT. To install the package, run this command:

pkg install zsh

The command looks like FreeBSD package manger (pkg). Or you can run this command:

apt update && apt upgrade
apt install zsh

To set zsh as your default shell, run this command:

chsh -s /data/data/com.termux/files/usr/bin/zsh

Or:

chsh -s $(which zsh)

Add yours

If you know a platform that is not covered, edit this page and add it!

Setup ZSH with help from oh-my-zsh

iTerm in action

Installing oh-my-zsh

Clone repository

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

Optional backup .zshrc config

cp ~/.zshrc ~/.zshrc.orig

Create a new zsh config by copying the zsh template oh-my-zsh provided

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Set zsh as your default shell

chsh -s /bin/zsh

Installing Powerline Themes

Clone repository

git clone https://github.com/jeremyFreeAgent/oh-my-zsh-powerline-theme.git ~/.oh-my-zsh-powerline-theme

Create symlink to oh-my-zsh themes folder

ln -f powerline.zsh-theme ~/.oh-my-zsh/themes/powerline.zsh-theme

Configure the theme in your .zshrc file

ZSH_THEME="powerline"

Install powerline fonts (pre-patched and adjusted fonts for usage with the new Powerline plugin). Download fonts from this repository:

https://github.com/Lokaltog/powerline-fonts

MAC: copy fonts to folder ~/Library/Fonts/

Linux: copy fonts to folder ~/.fonts/

Installing Custom Plugins for oh-my-zsh

Create custom plugins directory

mkdir ~/.oh-my-zsh/custom/plugins

zsh-syntax-highlighting

cd ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git

Others

Screenshot shown above:

iTerm
custom color schemes (based on Zenburn color schemes)
Menlo Regular for Powerline - 11pt

Example .zshrc

    # Path to your oh-my-zsh configuration.
    ZSH=$HOME/.oh-my-zsh

    # Configuration for powerline theme
    # Look in ~/.oh-my-zsh-powerline-theme
    POWERLINE_DETECT_SSH="true"
    POWERLINE_RIGHT_A="date"
    POWERLINE_HIDE_HOST_NAME="true"

    # Set name of the theme to load.
    # Look in ~/.oh-my-zsh/themes/
    ZSH_THEME="powerline"

    # Which plugins would you like to load? (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)
    plugins=(colored-man git history-substring-search sublime vagrant zsh-syntax-highlighting)

    source $ZSH/oh-my-zsh.sh

    # Customize to your needs...
    export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

    # Set 256 Color
    export TERM=xterm-256color

    # VirtualEnv
    if [ -z "$VIRTUALENVWRAPPER_PYTHON" ]
    then
        source /usr/local/bin/virtualenvwrapper.sh
    fi