Install ZSH on Linux and make it your default Shell
How to install and configure Zsh on Linux
Bash (Bourne Again Shell) is the default command-line shell on many distributions. Zsh (Z Shell) is a powerful shell that operates as both an interactive shell and as a scripting language interpreter.
Check your current shell:
> echo $SHELL
/usr/bin/bash
1. Z Shell
Please replace pacman in the following codelines by your distro package manager: apt, dnf etc.
Install the zsh
package:
$ sudo pacman -S zsh
Test it by running zsh
in your terminal. If you were using bash, you’ll switch to the zsh prompt. The prompt model will be different, since you’re using a different config file, not your classic .bashrc:
22:15 rphl ~ : echo $SHELL
/usr/bin/bash
22:15 rphl ~ : zsh
➜ ~
For basic configuration run the following command:
➜ ~ zsh /usr/share/zsh/functions/Newuser/zsh-newuser-install -f
Follow the recommended options, save and exit.
2. Oh-My-Zsh & plugins
Now, let’s install a powerful additional program: Oh My Zsh
A delightful community-driven (with 1,300+ contributors) framework for managing your zsh configuration. Includes 200+ optional plugins, over 140 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.
This framework will easily make Zsh friendlier by improving its usability, through plugins and themes.
zsh
, wget
and git
should be installed first. Install the program:
➜ ~ sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
I recommend installing 4 additional plugins that we’ll activate later through OMZ configuration file :
➜ ~ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
➜ ~ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
➜ ~ git clone https://github.com/agkozak/zsh-z $ZSH_CUSTOM/plugins/zsh-z
➜ ~ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
➜ ~ ~/.fzf/install
Fantastic search tool combined with fd
➜ ~ sudo dnf install fd-find
You’ll need to add the following lines at the end of .zshrc
export FZF_DEFAULT_COMMAND='fdfind --type f'
export FZF_DEFAULT_OPTS="--layout=reverse --inline-info --height=80%"
2. Configuring Zsh
For advanced configuration, modify the ~./zshrc
config file.
- Plugins (list of plugins): OMZ comes with a large list of plugins waiting to be activated by entering their names in the plugins section, as follow. In this section, add the name of the additional plugins we installed manually, in bold:
plugins=(
fzf
git
history-substring-search
colored-man-pages
zsh-autosuggestions
zsh-syntax-highlighting
zsh-z
)
- Theming (list of themes): enter the name of your favorite theme in the ZSH_THEME section:
# default theme
# ZSH_THEME="robbyrussell"ZSH_THEME="alanpeabody"
Would you want to modify some theme colors, ZSH use Spectrum. Get a list of colors code withb spectrum_ls
Copy your aliases from the .bashrc file into .zshrc, as well as other commands you may have created.
Tip: Apply the changes without needing to logout and then back in by running
source ~/.zshrc
.
4. Make Zsh default
On Manjaro, Fedora, Ubuntu… :
➜ ~ chsh -s $(which zsh)
Log out and log in back for the changes to take effect.
Enjoy!