How to Install Zsh on Ubuntu 24.04, 22.04 or 20.04

This guide will demonstrate how to install Zsh on Ubuntu 24.04, 22.04, or 20.04 LTS utilizing the command-line terminal with the APT Package Manager.

Zsh, or the Z Shell, is a powerful command-line shell that enhances the user experience with features not found in the default Bash shell. Its advanced scripting capabilities, theme support, and plugin ecosystem transform terminal interaction into a more efficient and enjoyable experience. With Zsh, users gain access to auto-completion, spell correction, and history sharing, making it a favorite among developers, system administrators, and power users.

Why Choose Zsh?

  • Auto-completion: Enhances productivity by suggesting commands and paths.
  • Themes and Plugins: Customize your terminal with a vibrant ecosystem.
  • Scripting Capabilities: Write powerful scripts with improved syntax.
  • Spell Correction: Mistypes are automatically corrected.
  • History Sharing: Access your command history across sessions.
  • Improved Variable Handling: Offers advanced features for handling variables.
  • Globbing Support: Use wildcards to match files and patterns efficiently.
  • Interactive Configuration: Easily configure Zsh with zshconfig.

Transitioning to Zsh on Ubuntu systems brings a blend of performance improvements and usability enhancements. Whether you’re a seasoned developer or a terminal novice, Zsh offers tools and features to suit your workflow.

Let’s dive into the installation process.

Install Zsh on Ubuntu via APT

Update Ubuntu Before Zsh Installation

We must first update all existing packages to ensure that the operating system is ready for the new installation. This step is crucial as it ensures your system is up-to-date, minimizing potential software conflicts and security vulnerabilities.

Execute the following commands to update your Ubuntu system:

sudo apt update
sudo apt upgrade

The sudo apt update command fetches the package lists from the repositories and updates them to get information on the newest versions of packages and their dependencies.

The sudo apt upgrade command installs new versions of packages that you already have, for new versions that require new dependencies.

Install Zsh on Ubuntu via APT Command

Having updated our Ubuntu system, we are now set to install ZSH. We’ll install ZSH on Ubuntu in this step through the default repositories. The advantage of this method is that it’s straightforward and doesn’t require any additional setup.

Run the following command to install ZSH:

sudo apt install zsh

In this command, sudo apt install zsh tells the package manager to install the ZSH shell package onto your system.

Verifying the ZSH Installation

We need to check its version to ensure that ZSH was installed successfully. This confirmation assures that ZSH is part of your system and gives you the specifics of the installed version.

Run the following command to confirm the installed version of ZSH:

zsh --version

The zsh --version command returns the version of ZSH installed on your system. This feedback provides confirmation that the installation process was successful and ZSH is ready for use.

Configure ZSH on Ubuntu

Now that ZSH is installed on your Ubuntu system, we can proceed to the initial configuration of ZSH. This stage involves running ZSH and following the setup prompts to tailor the shell to your needs.

Launch ZSH

You need to run the ZSH command to initiate the first-time setup process. The system then takes over, providing a series of prompts to guide you through the configuration.

Start the ZSH shell using the following command:

zsh

After executing the zsh command, you’ll be presented with a setup prompt:

Example output of a Zsh command in Ubuntu terminal.
Demonstrating Zsh command output on Ubuntu for enhanced terminal usage.

To commence the setup, type “1” and press Enter.

Configure ZSH Options

During the setup, ZSH will suggest configuring a few key options marked with a (Recommend) tag. These options include the configuration of history, auto-completion features, and speed improvements. While the prompts offer helpful instructions, it’s ultimately your decision on how to configure these settings.

For instance, choosing “1” might lead you through the history configuration:

Step-by-step Zsh configuration process on Ubuntu terminal.
A look at the Zsh configuration steps on an Ubuntu system.

After entering “1” to proceed with setup, Zsh presents several configuration options. Let’s break down some of these options:

  • History: This feature controls how Zsh manages the command history. You can customize settings like how many commands to keep in the history, how duplicates are handled, and whether to save the history between sessions.
  • Auto-completion: Zsh has robust features that complete commands and command options, filenames, and more. You can configure aspects like whether to ignore cases, how to handle ambiguous matches, and whether to list possible completions.
  • Speed Tricks: Various options can make Zsh feel more responsive. They include asynchronous completion of long-running commands and caching of command results.

Each option is interactive, and Zsh provides on-screen instructions and recommendations. So, don’t worry about getting everything perfect from the start.

Note: You can always run zsh-newuser-install -f to restart the setup process and try different settings.

You’re encouraged to review at least the first three options, which cover the most significant enhancements ZSH offers over the default BASH shell. Once you’ve finished the configuration, select “0” to save your options and exit the setup.

Fully customized Zsh terminal interface on Ubuntu.
The end result of a fully customized Zsh terminal on Ubuntu.

Post-Configuration Steps with Zsh

Once the initial setup is done, it won’t appear again. However, if you need to re-initialize the configuration, you can do so with the following commands:

autoload -Uz zsh-newuser-install
zsh-newuser-install -f

The autoload -Uz zsh-newuser-install command tells ZSH to load the zsh-newuser-install function when it’s first called. The zsh-newuser-install -f command forces the function to run, re-initializing the setup.

You are now operating within the ZSH terminal. If you wish to switch back to the BASH shell, use the exit command:

exit

To get back to the ZSH shell, use the following:

zsh

Managing Zsh on Ubuntu

The following instructions will guide you on handling Zsh updates and removals, ensuring your system remains up-to-date and uncluttered.

Update Zsh

In the lifecycle of any software, updates are integral to maintaining optimal functionality, performance, and security. The Zsh shell you’ve installed via Ubuntu’s repositories is no exception to this rule. Here’s how you keep your Zsh installation up-to-date.

sudo apt update
sudo apt upgrade

The sudo apt update command updates your local package index, ensuring your system knows about the latest versions of all packages available in the Ubuntu repositories. If updates are available, the sudo apt upgrade command that follows upgrades all your installed packages to their latest versions, including Zsh.

Uninstall Zsh

While Zsh offers numerous advantages over the standard Bash shell, it might not align with your preferences or project requirements. If you decide Zsh is not for you, it can be removed easily from your system. You can uninstall Zsh using the following command:

sudo apt remove zsh

This command instructs the package manager, apt, to remove the Zsh package. As a result, Zsh will be uninstalled, and your system will revert to using your previous default shell, typically Bash.

Closing Conclusion

In wrapping up, this guide walked you through the steps to install Zsh on Ubuntu, giving your terminal a major upgrade with its cool features like auto-completion and custom themes. Now that you’ve set it up, dive into customizing it to fit your workflow perfectly. Remember, Zsh isn’t just about making your terminal look good; it’s about making you more productive. So, play around with the plugins, explore the themes, and don’t hesitate to tweak your setup as you go. Happy tinkering, and enjoy the smoother, more powerful command-line experience Zsh brings to the table!

Leave a Comment