Install and Setup Zsh on Ubuntu

Envy the beautiful Z shell? Learn how to install zsh on Ubuntu and customize it with Oh My Zash.

Want to make your terminal look like this?

install zsh in ubuntu
Z shell

That's Z shell (zsh). While bash shell is omnipresent, zsh is a popular shell among developers.

But wait, why would anyone invest their time just for some punchy looks? Well, it's more than just looks.

The Zsh (Z shell) has a plethora of plugins and themes that primarily focus on decluttering unnecessary elements and some visual/performance tweaks for better productivity.

So in today's guide, I'll be walking you through the installation and some basic customization over Zsh that may serve as a base for limitless customization in the upcoming future.

Install Zsh on Ubuntu

Installation is quite simple as Zsh is available in the default Ubuntu repository.

While you can install zsh like this:

sudo apt install zsh

I recommend installing git and font awesome for additional customization I'll be showing in this tutorial.

sudo apt install zsh git fonts-font-awesome

The first run

Once you have zsh installed on your, you can start it in your terminal by typing this command:

zsh

And you'd met with the following screen:

Create bashrc file
Creating a .zshrc file by pressing 0

Zsh uses the .zshrc file for configuration and it gives you many options on how you want to manage the .zshrc file.

For this guide, I'm going with creating an empty .zshrc file by pressing 0.

So your default Zsh would look something like this:

Zsh terminal in ubuntu
The default look of Zsh

You didn't expect it to look this simple, did you?

Sit back and relax. You're about to have an eye candy terminal in no time.

Customizing your Zsh setup

Let's start with the installation of Oh My Zsh, a framework for Zsh that is a primary and integral part of this guide.

1. Installing Oh My Zsh in Ubuntu

I'm going with Oh My Zsh because it is a very efficient way to manage your configuration of Zsh.

Whether you want to change themes or plugins, Oh My Zsh will make it quite straightforward.

And you'll only need a single command for installation:

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

After installation, you'd be welcomed with a minimal theme which is a lot better than what Zsh offered us after the first installation:

Oh My Zsh
The minimal default look of Oh My Zsh

Well, the Oh My Zsh is only supposed to be a base for customization so you don't have to worry about its default looks.

DigitalOcean – The developer cloud
Helping millions of developers easily build, test, manage, and scale applications of any size – faster than ever before.
Get started on DigitalOcean with a $100, 60-day credit for new users.

2. Adding Auto Suggestion and Syntax Highlighting

Tired of writing the long command old way? try the auto-suggestion plug-in with syntax highlighting for enhanced workflow.

So let's start with downloading the auto-suggestion plugin:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Now, use the given command to download the syntax highlighting plugin:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Once you're done with the download part, you'll have to add downloaded plugins in the .zshrc file.

nano ~/.zshrc

and add zsh-syntax-highlighting and zsh-autosuggestions in plugins. Let me show you:

add plugins in zshrc file
Adding plugins to .zshrc config file

Save the config file and restart the terminal and your terminal should look like this:

auto suggestion and syntax highlighting plugin in zsh
Syntax highlighting and auto suggestion in Zsh 

3. Adding Powerlevel10k Theme

This part is where you'll be the one deciding how you want your terminal looks.

Because the Powerlevel10k has a plethora of options that will result in how your terminal is themed and all of them can't be covered in this guide.

So let's start with the installation:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Now, you'll have to change the default theme in the ./zshrc file to powerlevel10k To open the config file, use the given command:

nano ~/.zshrc

Your default Zsh theme will be robbyrussell which you'll have to interchange with powerlevel10k/powerlevel10k as shown in the image:

add themes in zshrc file in Zsh
Adding Powerlevel10k theme to .zshrc file 

Save the config file and restart your terminal. You'll be welcomed with the given screen:

setup zsh in ubuntu

It will ask you whether the given icon resembles a diamond or not. For me it's not so I'll go with n.

how to configure zsh in linux

Similarly, there's another question "Does this look like a lock?" For me, its yes so I'd be entering y.  

powerlevel10k theme in zsh for ubuntu

This is the last question where you have to answer whether icons fit between crosses. They're overlapped in my case so I'd be entering n.

customise zsh using powerlevel10k theme
Available prompt styles

From here on, you'd be given multiple options such as prompt style and so on. Select what works for you and I'll be skipping to the end part to save the configuration.

Once you're done with all the choices, you'd be given the following prompt:

prompt mode in powerlevel10k theme zsh
Instant prompt mode

I'd highly recommend you go with 1st option verbose as you'd have a backup config file that allows you to reset the choices you went with in Powerlevel10k.

save changes in zshrc file
Apply changes to .zshrc file

Now, you can save the config file by pressing y.

And it will show you where the backup and new config file reside.

new config and backup config file of Zsh

Want to start configuring Powerlevel10k from scratch again? just use the given command and the configuration process would start from the beginning:

p10k configure

But wait, as I told you earlier, this is just a basic customization guide and you can try different themes from Zsh's them section on GitHub.

MEGA
MEGA provides free cloud storage with convenient and powerful always-on privacy. Claim your free 20GB now

Make zsh your default shell

If you like the zsh shell, you can make it your login shell, i.e., your default shell so that whenever you open the terminal or log into your system via SSH, you are logged into Zsh.

To change the shell, enter this command:

chsh

It will show you the default shell (bash for the majority) which you've to change to /bin/zsh.

Let me show you how:

Change default shell in ubuntu
Changing the default shell to Zsh

You'll have to log out and back in to apply these changes.

Conclusion

You learned to install Zsh on Ubuntu and configure it properly and beautifully with Oh My Zsh.

The Zsh can be considered a DIY shell as you have access to numerous plugins and themes that there's nothing left to complain about but just adore your terminal.

If you have any queries, feel free to ask in the comments below.