1080*80 ad

Installing and Configuring ZSH and Oh-My-Zsh on Ubuntu 18.04

Supercharge Your Ubuntu Terminal: The Ultimate Guide to Zsh and Oh-My-Zsh

If you spend a significant amount of time in the command line on Ubuntu, you know that the default Bash shell is functional, but it leaves much to be desired. For developers, system administrators, and power users, a more powerful and intuitive shell can dramatically improve productivity and workflow.

Enter Zsh (the Z Shell), a robust and highly customizable shell that offers a significant upgrade over Bash. When paired with the Oh-My-Zsh framework, it transforms the standard terminal into a smart, efficient, and visually appealing workspace.

This guide will walk you through everything you need to know to install, configure, and master Zsh and Oh-My-Zsh on your Ubuntu system.

What is Zsh and Why Should You Switch?

Zsh is a Unix shell that can be used as an interactive login shell and a command interpreter for shell scripting. It incorporates many of the best features from other shells like Bash, KornShell (ksh), and tcsh, while adding a host of its own powerful capabilities.

Key advantages of using Zsh include:

  • Advanced Tab Completion: Zsh offers intelligent, programmable command-line completion that can complete arguments, options, and filenames with incredible accuracy.
  • Smarter Globbing: Easily work with files and directories using recursive globbing (**/*) without complex find commands.
  • Powerful Plugin Support: Extend the shell’s functionality with thousands of community-built plugins for git, Docker, Python, and more.
  • Extensive Theme Support: Customize your command prompt’s appearance with a vast library of themes to show git status, virtual environments, and other useful information.
  • Automatic Spelling Correction: Zsh can automatically correct minor typos in your commands, saving you time and frustration.

Step 1: Installing Zsh on Ubuntu

Before you can use Zsh, you need to install it. The process is straightforward using Ubuntu’s default package manager.

First, open your terminal and ensure your package list is up to date.

sudo apt update

Next, install the Zsh package.

sudo apt install zsh

Once the installation is complete, you can verify it by checking the installed version.

zsh --version

This command should return the version number of Zsh, confirming that it’s successfully installed on your system.

Step 2: Setting Zsh as Your Default Shell

While Zsh is now installed, your terminal will continue to use Bash by default. To make Zsh your permanent shell, you need to change it for your user account.

Run the following command, which uses chsh (change shell) to set the path to the Zsh executable as your default.

chsh -s $(which zsh)

You will be prompted to enter your password. After you do, you must log out and log back in for the change to take effect. Open a new terminal, and you should be greeted by the Zsh first-time configuration prompt. You can choose option (2) to populate your .zshrc file with the recommended default settings.

Step 3: Installing Oh-My-Zsh for Effortless Configuration

Zsh is powerful on its own, but configuring it manually can be complex. This is where Oh-My-Zsh, a community-driven framework for managing your Zsh configuration, comes in. It simplifies the process of using themes, plugins, and custom scripts.

Before installing Oh-My-Zsh, make sure you have git and curl installed.

sudo apt install git curl

Now, you can install Oh-My-Zsh using the official installer script via curl.

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

This script will download Oh-My-Zsh and create a configuration file at ~/.zshrc. If you already have a .zshrc file, it will be backed up. Once complete, your terminal will immediately look different, as Oh-My-Zsh applies a default theme.

Step 4: Customizing Your Terminal with Themes and Plugins

The true power of this setup lies in customization. All your configurations are managed in the ~/.zshrc file. You can open it with any text editor, such as nano.

nano ~/.zshrc

Changing Your Theme

Oh-My-Zsh comes with hundreds of pre-installed themes. The default is robbyrussell. To change it, find the line ZSH_THEME="robbyrussell" in your .zshrc file and replace the theme name.

A highly popular and powerful theme is agnoster.

ZSH_THEME="agnoster"

Security Tip: Some themes, including agnoster, require Powerline-patched fonts to display special characters like branch icons and prompt symbols correctly. You can install these with a simple command:
sudo apt install fonts-powerline
After installing the fonts, you may need to update your terminal’s profile settings to use one of them (e.g., Ubuntu Mono derivative Powerline).

Save the .zshrc file (Ctrl+X, then Y, then Enter in nano) and apply the changes by running:

source ~/.zshrc

Activating Essential Plugins

Plugins add new features and aliases to your shell. Oh-My-Zsh enables the git plugin by default, which provides useful aliases and functions for Git. You can enable more plugins by adding their names to the plugins array in your .zshrc file.

Look for this line:

plugins=(git)

Here are two highly recommended plugins to start with:

  1. zsh-autosuggestions: This plugin suggests commands as you type based on your history, which you can complete by pressing the right arrow key.
  2. zsh-syntax-highlighting: This provides real-time highlighting for commands, helping you spot syntax errors before you even hit enter.

First, you need to clone these plugins into the Oh-My-Zsh custom plugins directory.

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

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

Next, open your .zshrc file again and add them to the plugins list.

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

Save the file and reload your configuration with source ~/.zshrc. Now, your terminal will feature syntax highlighting and intelligent command suggestions.

Keeping Your Setup Updated

Oh-My-Zsh makes it easy to stay current with the latest themes and plugins from the community. To update the framework, simply run:

omz update

This command will pull the latest changes for the core framework as well as any installed plugins and themes.

A More Powerful Command Line Awaits

By investing a few minutes to install and configure Zsh and Oh-My-Zsh, you unlock a significantly more powerful, efficient, and personalized command-line experience on Ubuntu. With features like intelligent auto-completion, helpful plugins, and informative themes, you can streamline your workflow and spend less time fighting your terminal and more time getting things done. Explore the vast ecosystem of plugins and themes to tailor your shell perfectly to your needs.

Source: https://kifarunix.com/how-to-install-and-setup-zsh-and-oh-my-zsh-on-ubuntu-18-04/

900*80 ad

      1080*80 ad