Website Vidya
Linux & ServersStep-by-Step Guide

How to Install and Use Zsh on Ubuntu

Learn how to install and use zsh on ubuntu with Oh My Zsh framework, zsh-autosuggestions, syntax highlighting, and custom terminal themes.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install and Use Zsh on Ubuntu
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to install and use zsh on ubuntu with Oh My Zsh framework, zsh-autosuggestions, syntax highlighting, and custom terminal themes.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Zsh and Prerequisite Packages
  • Step 2: Setting Zsh as Your Default Login Shell
Grounded in full engineering runbookWebsiteVidya AI Engine

The default command shell on Ubuntu is Bash (Bourne Again SHell), a battle-tested and reliable tool for general system administration.

However, developers and system administrators who spend hours every day inside a terminal shell frequently seek productivity enhancements.

Zsh (Z Shell) is an advanced interactive shell designed with powerful autocomplete algorithms, intelligent path expansion, spelling correction, and extensive plugin capabilities.

When paired with the popular open-source Oh My Zsh framework, Zsh transforms the Linux command line into a modern, customizable development environment.

Advertisement

In this guide, we walk through how to install and use zsh on ubuntu, set it as your default login shell, install themes, and enable high-productivity plugins.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

Advertisement
  • A computer or server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • An unprivileged user account with sudo administrative privileges.
  • Git and curl installed on the system.
  • Access to a terminal window or SSH session.

Step 1: Installing Zsh and Prerequisite Packages

Ubuntu repositories package Zsh natively in the main component.

First, refresh your local package index, then install zsh along with curl and git:

# Update package index:
sudo apt update

# Install Zsh, Git, and Curl:
sudo apt install -y zsh git curl

# Verify installed Zsh version:
zsh --version
# Expected output: zsh 5.9 (x86_64-ubuntu-linux-gnu)

Step 2: Setting Zsh as Your Default Login Shell

Installing Zsh does not automatically replace Bash as your default login shell.

Use the chsh (change shell) utility to update your user account record in /etc/passwd:

Advertisement

Specify the absolute path to the Zsh binary (/bin/zsh or /usr/bin/zsh):

# Identify the binary path of Zsh:
which zsh
# Output: /usr/bin/zsh

# Change the default shell for the CURRENT user (NO sudo!):
chsh -s $(which zsh)

# Confirm that /etc/passwd reflects the new default shell:
grep $USER /etc/passwd
# Output: sysadmin:x:1001:1001:sysadmin,,,:/home/sysadmin:/usr/bin/zsh

Activating Your New Shell Session

Log out of your terminal session and log back in, or launch Zsh directly in your current session by typing zsh:

# Launch Zsh immediately:
zsh

# Verify the active running shell environment variable:
echo $SHELL
# Output: /usr/bin/zsh

Step 3: Installing the Oh My Zsh Framework

Oh My Zsh is a community-driven framework for managing your Zsh configuration with hundreds of plugins and themes.

Run the automated installation script via curl from your terminal:

# Install Oh My Zsh via official automated script:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Expected confirmation ASCII banner:
#   ____  / /_     ____ ___  __  __   ____  _____/ /_
#  / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
# / /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
# \____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
#                         /____/

Step 4: Configuring Themes and Productivity Plugins

The main Zsh user configuration file resides at ~/.zshrc.

Two essential plugins that dramatically accelerate terminal productivity are zsh-autosuggestions (which suggests commands as you type based on your history) and zsh-syntax-highlighting (which highlights valid commands in green and errors in red).

Clone both plugins into the custom plugin directory:

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

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

Enabling Plugins in ~/.zshrc

Open ~/.zshrc and update the plugins=(...) array to enable your installed extensions:

Remember that zsh-syntax-highlighting must always be the last plugin in the list:

# In ~/.zshrc, update the plugins line:
plugins=(
  git
  sudo
  copypath
  copyfile
  zsh-autosuggestions
  zsh-syntax-highlighting
)

# Apply configuration changes immediately:
source ~/.zshrc

Practical Zsh Productivity Features and Shortcuts

Zsh introduces several powerful command-line features that make navigation significantly faster than standard Bash:

Review this summary of daily productivity shortcuts enabled in Zsh:

Feature / ShortcutZsh BehaviorExample Usage
Tab Completion MenuInteractive arrow-key navigation through directories and flagsType cd /v/w/ and press Tab to expand to /var/www/
Spelling Auto-CorrectionPrompts with suggested corrections for mistyped commandsType sl -> prompts correct 'sl' to 'ls' [nyae]?
Directory Auto-JumpType directory name directly without the cd commandType /etc/nginx and press Enter
Double-Esc for SudoPress Esc twice to prepend sudo to current or previous commandQuickly elevate forgotten sudo commands

Step 5: Configuring Custom Aliases and Reverting to Bash

You can configure shell shortcuts and environment variables by adding custom alias definitions directly at the bottom of your ~/.zshrc file.

Add time-saving command aliases for common administrative operations:

If you ever need to revert your default login shell back to Bash, invoke chsh again with the path to the Bash executable:

# Add custom aliases to ~/.zshrc:
cat << 'EOF' >> ~/.zshrc

# Useful sysadmin aliases:
alias ll='ls -lah --color=auto'
alias update='sudo apt update && sudo apt upgrade -y'
alias ports='sudo ss -tulpn'
EOF

# Apply updated aliases:
source ~/.zshrc

# To revert your default login shell back to Bash at any time:
chsh -s /bin/bash

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

chsh: PAM: Authentication failure

Cause: Entering the wrong user password when invoking chsh.

Resolution: Ensure you enter your current user's password, or change the shell with root privileges: sudo chsh -s /bin/zsh username.

sudo chsh -s $(which zsh) $USER

Corrupted characters or question marks in prompt theme

Cause: The active theme requires a Powerline or Nerd Font that is not installed on your client terminal.

Resolution: Switch to a non-font-dependent theme like ZSH_THEME="robbyrussell" or install a Nerd Font (e.g. MesloLGS NF) on your local terminal.

sed -i 's/ZSH_THEME=".*"/ZSH_THEME="robbyrussell"/' ~/.zshrc && source ~/.zshrc

Slow terminal startup with Oh My Zsh

Cause: Too many active plugins or slow Git status parsing on large repositories.

Resolution: Disable unnecessary plugins in ~/.zshrc and benchmark startup using time zsh -i -c exit.

time zsh -i -c exit

Security Best Practices and Hardening

Always inspect external shell installation scripts before piping them into sh or bash.

Avoid storing plaintext passwords or sensitive API tokens directly in ~/.zshrc; use external environment files with restricted permissions.

Regularly update Oh My Zsh and plugins by running omz update.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
No. Shell scripts specify their interpreter on line 1 using a shebang (e.g. #!/bin/bash). Ubuntu always executes those scripts with /bin/bash regardless of your interactive login shell.
Run chsh -s /bin/bash in your terminal and log out. Your default shell will immediately return to standard Bash.
Simply run omz update in your terminal. It pulls the latest upstream commits from GitHub and updates your installation automatically.
Yes. In your ~/.zshrc, add the line: [ -f ~/.bash_aliases ] && source ~/.bash_aliases to inherit all your existing aliases.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout