How to Install Oh My Zsh on Ubuntu 22.04 (Step-By-Step Oh My Zsh Installation Guide)
How to Install Oh My Zsh on Ubuntu 22.04 (Step-By-Step Oh My Zsh Installation Guide)
Z Shell (Zsh) is an interactive Unix shell known for its command interpretation and shell scripting capabilities. It’s an enhanced Bourne shell, featuring improvements from Bash, ksh, and tcsh. Zsh offers advantages such as command-line completion, shared history, intelligent tab completion, spelling correction, and a vast array of plugins and themes.
This tutorial will guide you through installing Oh My Zsh on Ubuntu 22.04, allowing you to leverage Zsh’s powerful features for a better command-line experience.
What Is the Difference Between Zsh and Bash?
Both Zsh and Bash are popular open-source command-line interpreters. Zsh is designed to be backward compatible with Bash, ensuring a smooth transition for users familiar with Bash syntax. The key difference lies in Zsh’s extensive customization features, allowing users to personalize their shell experience with themes and a variety of plugins.
Prerequisites
An Ubuntu 22.04 system or a virtual machine.
Root or sudo privileges.
Installing Zsh on Ubuntu 22.04
Step 1: Update Your System
Before installing Zsh, update your software repositories. Open your terminal and run:
sudo apt update
Step 2: Install Required Packages
Next, install the necessary dependencies:
sudo apt install build-essential curl file git
Step 3: Install Zsh
Now, install Zsh from the official Ubuntu repositories:
sudo apt install -y zsh
Step 4: Verify the Installation
To confirm that Zsh is installed, check the version:
zsh –version
You can also check the binary path:
which zsh
This should return /usr/bin/zsh. Use the whereis command for further verification:
whereis zsh
Step 5: Set Zsh as Your Default Shell
Set Zsh as your default shell with the following command:
sudo chsh -s /usr/bin/zsh
After restarting your terminal, confirm the change:
echo $SHELL
Installing Oh My Zsh
Oh My Zsh is an open-source framework designed to enhance Zsh’s functionality, providing an easy way to manage themes, plugins, and scripts.
Step 1: Install Curl or Wget
If you haven’t installed curl yet, do so now:
sudo apt install curl
Step 2: Install Oh My Zsh
You can install Oh My Zsh using the following command:
sh -c “$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)”
During installation, confirm by pressing “Y” when prompted.
Configuring Oh My Zsh
Plugins
Oh My Zsh comes with over 300 pre-configured plugins. To enable plugins, edit the .zshrc file:
nano ~/.zshrc
Find the plugins line and add your desired plugins:
plugins=(git zsh-autosuggestions)
After modifying, save the file and refresh the configuration:source ~/.zshrc
Themes
To change your Oh My Zsh theme, locate the ZSH_THEME line in your .zshrc file:
ZSH_THEME=”agnoster”
Change “agnoster” to your preferred theme. For a random selection, use:
ZSH_THEME_RANDOM_CANDIDATES=(“agnoster” “robbyrussell”)
ZSH_THEME=”random”
Auto-Suggestions Plugin
To enable auto-suggestions based on your command history, clone the repository:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Add zsh-autosuggestions to your plugins in the .zshrc file, save, and refresh.
Syntax Highlighting
Clone the syntax highlighting repository:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Add zsh-syntax-highlighting to your plugins in .zshrc, save, and refresh.
Additional Plugin Configuration
Dirhistory Plugin: For directory navigation.
History Plugin: Offers convenient aliases for command history.
Colored Man Pages Plugin: Improves readability of help pages.
Automatic Updates
Oh My Zsh updates automatically every two weeks. To customize or disable updates, edit the .zshrc file.
Uninstalling Oh My Zsh
To remove Oh My Zsh and its components:
sudo apt –purge remove zsh
To switch back to Bash:
chsh -s $(which bash)
Conclusion
You’ve successfully installed and configured Oh My Zsh on Ubuntu 22.04. While Bash remains widely used, Zsh’s features make it a compelling alternative. Customize your Zsh environment further to enhance your command-line productivity.