How to Install and Use Zsh on Ubuntu

By 

Published on

6 min read

Install and use Zsh on Ubuntu

Bash has been the default login shell on Ubuntu for years, and it works fine for running scripts and one-off commands. When we spend most of the day inside a terminal, though, small details start to matter: smarter tab completion, spell correction on commands, recursive globs, and rich theming. Zsh adds those features without breaking the Bash scripts we already rely on.

This guide explains how to install Zsh on Ubuntu, set it as the default shell, configure ~/.zshrc, and bolt on the Oh My Zsh framework for plugins and themes.

Quick Reference

TaskCommand
Install Zshsudo apt install zsh
Check versionzsh --version
Set as default shellchsh -s $(which zsh)
Reload configsource ~/.zshrc
List shellscat /etc/shells
Switch back to Bashchsh -s /bin/bash
Install Oh My Zshsh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Prerequisites

You need an Ubuntu system with a user account that has sudo privileges. The Zsh package comes from the default Ubuntu repositories, while the Oh My Zsh installer needs curl and git.

Install those helper packages if they are missing:

Terminal
sudo apt update
sudo apt install curl git

Install Zsh

Zsh is available in the default Ubuntu repositories. Refresh the package index and install it:

Terminal
sudo apt update
sudo apt install zsh

Verify the installation by checking the Zsh version:

Terminal
zsh --version

The output looks similar to:

output
zsh 5.9 (x86_64-ubuntu-linux-gnu)

Run Zsh for the First Time

Start Zsh without changing your default shell yet:

Terminal
zsh

The first launch opens the zsh-newuser-install configuration wizard. The relevant choices are:

  • 0 exits the wizard and creates an empty ~/.zshrc so Zsh stops asking on every start.
  • 1 continues to the interactive menu, where we can pick defaults for history, completion, key bindings, and a few other behaviors.
  • 2 populates ~/.zshrc with the system-wide recommended defaults.
  • q quits without creating a config file at all, which means the wizard runs again next time.

Pick option 0 or q if you plan to install Oh My Zsh next, since it ships its own template and will overwrite the file anyway. Otherwise, run the interactive setup to generate a sensible starting point.

Set Zsh as the Default Shell

Once you are happy with the way Zsh behaves, change the default login shell for your user:

Terminal
chsh -s $(which zsh)

Log out and log back in so the new shell takes effect. Confirm the change with:

Terminal
echo $SHELL

The output should be /usr/bin/zsh or /bin/zsh, depending on your Ubuntu release and shell path layout.

If you prefer to keep Bash as the login shell and only run Zsh on demand, skip this step and start Zsh manually with zsh whenever you need it.

Edit ~/.zshrc

The ~/.zshrc file runs every time an interactive Zsh session starts. Open it with your editor:

Terminal
nano ~/.zshrc

A minimal useful starting point looks like this:

~/.zshrcsh
# History
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS

# Completion
autoload -Uz compinit
compinit

# Aliases
alias ll='ls -lah'
alias gs='git status'

# Prompt
PROMPT='%n@%m %~ %# '

Reload the file in the current session without opening a new terminal:

Terminal
source ~/.zshrc

For more on aliases, see how to create Bash aliases . The same syntax works in Zsh.

Install Oh My Zsh

Oh My Zsh is a popular framework that ships a large catalog of plugins and themes. The official installer is the most common setup path:

Warning
Piping a remote install script into sh runs code from the network as your user. If you are setting up a shared or production machine, download the installer first, review it, and then run it locally.

To inspect the script before running it, use:

Terminal
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o install-oh-my-zsh.sh
less install-oh-my-zsh.sh
sh install-oh-my-zsh.sh

For a quick personal workstation setup, you can run the installer directly:

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

The installer clones Oh My Zsh into ~/.oh-my-zsh, backs up the existing ~/.zshrc to ~/.zshrc.pre-oh-my-zsh, and writes a new ~/.zshrc with sensible defaults.

Pick a Theme

Open ~/.zshrc and find the ZSH_THEME line. The default value is robbyrussell. Try a different theme by setting:

sh
ZSH_THEME="agnoster"

The agnoster theme uses powerline-style segments and requires a Nerd Font for the special glyphs. If you want to sample themes without installing extra fonts first, use ZSH_THEME="random" to cycle themes on every login until you find one you like.

Reload the configuration to apply the new theme:

Terminal
source ~/.zshrc

Enable Plugins

Plugins extend Zsh with completion definitions, shortcuts, and visual aids. Edit the plugins=() line in ~/.zshrc and add the plugins you want:

sh
plugins=(git docker kubectl sudo zsh-autosuggestions zsh-syntax-highlighting)

git, docker, kubectl, and sudo ship with Oh My Zsh. zsh-autosuggestions and zsh-syntax-highlighting are external plugins. Install them with:

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

Reload ~/.zshrc to activate them:

Terminal
source ~/.zshrc

zsh-autosuggestions shows a faded completion based on your history as you type. Press the right arrow key to accept it. zsh-syntax-highlighting colors valid commands green and unknown commands red, which catches typos before you press Enter.

Useful Built-in Features

Zsh ships several features that are not available in Bash without extra setup:

  • Recursive glob patterns: ls **/*.log lists every .log file under the current directory.
  • Globbing qualifiers: ls *(.) lists only regular files; ls *(/) lists only directories.
  • Spell correction: setopt CORRECT prompts you to fix mistyped commands.
  • Sharing history across sessions in real time with setopt SHARE_HISTORY.

Troubleshooting

chsh reports “non-standard shell”
Make sure /usr/bin/zsh is listed in /etc/shells. If it is missing, add it with echo $(which zsh) | sudo tee -a /etc/shells and run chsh again.

Zsh starts but the prompt is broken on a remote SSH session
The theme probably depends on a Nerd Font that the local terminal does not have. Switch to a simpler theme such as robbyrussell or install a Nerd Font in the terminal application.

Plugins are listed but nothing happens
Check the ZSH_CUSTOM path matches where you cloned the plugin. Run ls ~/.oh-my-zsh/custom/plugins to confirm the plugin directory exists, then reload ~/.zshrc.

Conclusion

From here we can keep tweaking ~/.zshrc to match the way we work: add aliases for repetitive commands, pin a theme that reads well in the terminal we use most, and pull in plugins as new tools enter the workflow. The alias syntax matches Bash, so existing alias workflows carry over without changes.

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page