This tutorial will guide you through steps to Install Zsh on Linux and Configure it to suit your needs.
Definition of shell from Wikipedia:
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering commands as a text for a command line interpreter to execute or by creating text scripts of one or more such commands.
Most fresh installation of Linux comes pre-loaded with a Bash shell. Personally, I like zsh, and it’s my favorite shell that I use all the time.
Zsh does a bunch of other useful things that bash alone won’t accomplish.
Apart from being a powerful scripting language, Zsh is a shell designed for interactive use. It incorporates into it many useful features of Bash, ksh, and tcsh. Other additional features provided by zsh are:
- Auto Completions are case insensitive much faster than bash.
- All sorts of bells and whistles made possible by a community-driven framework like oh-my-zsh.
- Support multi-line editing
- Recursive file globbing
- Highly compatible with ksh.
- Zsh has a huge collection of better themes.
- Simple configuration style
- Output redirection to multiple destinations
And many more, do some googling to learn more. Here you’ll Install Zsh on Linux.
Install Zsh on Linux
sudo pacman -S zsh
emerge --ask zsh
sudo apt-get install zsh
sudo dnf install zsh
yum install zsh
yum install zsh
Check and Change shell to Zsh
Confirm it’s installed and see a list of installed shells. After you successfully Install Zsh on Linux, you should see version displayed.
zsh --version chsh -l
After you’ve installed it, we need to make it our default shell and customize it to get extra eye-candy. We’ll change the shell for both root and standard user account.
[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”usermod%20username%20-s%20%2Fusr%2Fbin%2Fzsh%0A”/]
[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”chsh%20-s%20%2Fusr%2Fbin%2Fzsh%20username%0A”/]
Install Oh My Zsh
The easiest way to customize zsh is to install Oh My Zsh to set zsh theme. Oh My Zsh is an open source, a community-driven framework for managing your zsh configuration. It comes with a load of plugins and themes to take advantage of. Install it as below.
Make sure you have all above prerequisites installed on your system.
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
Once installed, you’ll get a bundle of themes that comes with it, located at ~/.oh-my-zsh/themes/
[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”ls%20-l%20~%2F.oh-my-zsh%2Fthemes%2F”/]
You can also take a look in the plugins directory to see all plugins available.
ls -lh ~/.oh-my-zsh/plugins
Install Oh My Zsh themes for Zsh
We’ll install my favorite theme to ~/.oh-my-zsh/themes/ and configure .zshrc to use it.
cd ~/.oh-my-zsh/themes/ git clone https://github.com/oskarkrawczyk/honukai-iterm-zsh.git cp honukai-iterm-zsh/honukai.zsh-theme ~/.oh-my-zsh/themes/
Modify theme variable name to ZSH_THEME=”honukai” in ~/.zshrc
See screenshot below,
Save changes and exit. Type CTRL+X, Then Y.
Source ~/.zshrc file
Configure Help command.
Add the following lines to the end.
autoload -U run-help autoload run-help-git autoload run-help-svn autoload run-help-svk alias help=run-help
Source it and you’re good to go.
Fish-like syntax highlighting (Optional)
cd ~/.oh-my-zsh/plugins git clone https://github.com/zsh-users/zsh-syntax-highlighting.git nano ~/.zshrc
Add below the line at the end,
Then source zshrc file
Persistent rehash: This allows compinit to automatically find new executables in the $PATH.
zstyle ':completion:*' rehash true
Save and exit, the source it.
Configure additional zsh-completions, applicable to all Linux systems.
I will assume you already installed oh-my-zsh, if not refer to it above.
git clone https://github.com/zsh-users/zsh-completions ~/.oh-my-zsh/custom/plugins/zsh-completions
Then enable it in your .zshrc
plugins+=(zsh-completions) autoload -U compinit && compinit
zsh tab-completion system
To enable the famous zsh tab-completion system, you need to add above commands ( autoload -U compinit && compinit).
If you are running Arch Linux, you can install it using Pacman package manager. This has an advantage of getting updates for it automatically.
pacman -S zsh-completions
Installing zsh-completions on Gentoo
emerge --ask zsh-completions
Install zsh-completions on Fedora / CentOS / RHEL / Scientific Linux:
cd /etc/yum.repos.d/ wget https://download.opensuse.org/repositories/shells:zsh-users:zsh-completions/RHEL_7/shells:zsh-users:zsh-completions.repo yum install zsh-completions
When you use Pacman and emerge, it will enable it automatically on zshrc file.
To uninstall oh-my-zsh type
rm -rf ~/.oh-my-zsh
We’ve covered how to Install Zsh on Linux and configuring Zsh environment on your system. Zsh is the most customizable shell I have ever used. It’s easy to install and customize with more than 100 themes. There are plenty of plugins to extend its functionality with frameworks like oh-my-zsh.