Installing ZSH, Oh-my-Zsh on Ubuntu, MacOS

Installing ZSH, Oh-my-Zsh on Ubuntu, MacOS

·

4 min read

Oh-My-Zsh is a framework for Zsh, the Z shell.

1. Install and set up zsh as default

Installation is straightforward with the apt command:

sudo apt install zsh

Verify installation by running

zsh --version

Expected result: zsh 5.8 or more recent.

Make it your default shell:

chsh -s $(which zsh)

Note that this will not work if Zsh is not in your authorized shells list (/etc/shells) or if you don't have permission to use chsh. If that's the case you'll need to use a different procedure. Log out and log back in again to use your new default shell. Test that it worked with echo $SHELL. Expected result: /bin/zsh or similar. Test with $SHELL --version. Expected result: 'zsh 5.4.2' or similar

2. Install oh-my-zsh and Powerline fonts

Install oh-my-zsh for more beautiful terminal

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

The output will be colorful like this

During the installation process, you will be asked to change the default shell from bash to zsh. Choose Y for changing to zsh.

Using apt command for installing Powerline fonts

sudo apt-get install powerline fonts-powerline

On other environments, you can copy and paste these commands to your terminal. Comments are fine too.

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

3. Install the most useful plugins for zsh

The most useful plugins for zsh are syntax highlighting and autosuggestions.

sudo apt install zsh-syntax-highlighting zsh-autosuggestions

Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc):

nano ~/.zshrc

Find the line of enable plugins and add zsh-autosuggestions and zsh-syntax-highlighting

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

Ctrl+X to close nano editor with key Y to save changes. After all, reload zsh to enable plugins with command

source ~/.zshrc

If for some reasons, plugins could not install, do it manually by downloading them and putting them in the correct path.

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

4. Using a fancy theme for zsh

Open .zshrc file using nano editor

nano ~/.zshrc

Find the line ZSH_THEME="robbyrussell" and replace robbyrussell with agnoster theme in .zshrc File. After that press CTRL + X then Enter to Save.

By default, your terminal uses the font Courier New for display, which makes zsh text before the cursor unreadable with unknown symbols.

For fixing this, Powerline fonts need to be installed and modify the color of Ansi Blue.

Installing Powerline fonts

On Windows 10, installing Powerline fonts can be done by following these steps:

  1. Download and extract zip from here

  2. Press Windows + x

  3. Press a (Selects PowerShell (Admin))

  4. Navigate to directory where fonts were extracted to (cd ${HOME}\Downloads\fonts-master\fonts-master)

  5. Set Execution policy Set-ExecutionPolicy Bypass

  6. Press y then Enter to accept

  7. Run the install file .\install.ps1

  8. Reset Execution policy Set-ExecutionPolicy Default

  9. Press y then Enter to accept

  10. Remove the fonts folder (cd ../.. && Remove-Item -Recurse -Force fonts-master)

Change terminal color and font

Open Putty/Window/Appearance and change font to Source Code Pro for Powerline - Regular

After that, change the ANSI Blue to a brighter color

But this change is applied only this time when you log in to your Linux Machine. To make this change permanent the logging session needs to be saved.

If you follow the previous steps, you'd have something like this

For MacOs and Linux users, the same process needs to be done

  • Install Powerline fonts

  • Change the default font of the terminal to Powerline font

  • Set ANSI blue color to brighter color

    If the username and host always display at the beginning of the prompt make you feel annoyed, you can remove it permanently by following these steps:

    nano ~/.oh-my-zsh/themes/agnoster.zsh-theme
    

    Go to the bottom of file and comment out the line "prompt_context"

Reload the shell and enjoy!

source ~/.zshrc

Resources: