Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Install Zsh First

The installer also needs Git and curl. On Ubuntu and Debian:

sudo apt install zsh git curl

On AlmaLinux and Rocky Linux:

sudo dnf install zsh git curl

Check the version with zsh --version. How Zsh differs from Bash and other shells is covered in types of shells in Linux.

Make Zsh Your Login Shell

chsh -s "$(command -v zsh)"

The path must be listed in /etc/shells; the package adds it. The change takes effect at your next login. Log out, log in again, and check with echo $SHELL. The Oh My Zsh installer also offers to make this change for you.

Install Oh My Zsh

Run the installer as your own user, not with sudo. Download it, read it, then run it:

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

The script clones the project into ~/.oh-my-zsh, keeps a copy of an existing ~/.zshrc as ~/.zshrc.pre-oh-my-zsh, and writes a new ~/.zshrc.

The Settings in .zshrc

LineWhat it sets
ZSH_THEME="robbyrussell"The prompt theme
plugins=(git)Plugins to load
source $ZSH/oh-my-zsh.shLoads the framework

Change the theme and plugins above the source line, then reload with exec zsh. Bundled themes are in ~/.oh-my-zsh/themes. Some, such as agnoster, need a Powerline font in the terminal on your own computer, or the prompt shows broken symbols.

Add Plugins

Many plugins come bundled: git adds Git aliases, docker and kubectl add completion, sudo adds a key shortcut to put sudo in front of a command. List them separated by spaces:

plugins=(git docker sudo)

Two popular outside plugins are installed by cloning them into the custom folder:

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 \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Then add them to the plugins line, with syntax highlighting last, as its project asks:

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

Outside plugins run every time a shell starts. Install only ones you trust, from their official repositories.

Update and Uninstall

  • Update: omz update pulls the latest version. By default Oh My Zsh also checks for updates every two weeks and asks before updating.
  • Uninstall: uninstall_oh_my_zsh removes the framework and restores your previous .zshrc if one was saved.
  • Back to Bash: chsh -s /bin/bash.

Keep Start-Up Fast

Each plugin and theme adds a little time to every new shell. Measure it:

time zsh -i -c exit

If a new shell takes noticeably long, remove plugins you do not use and try a simpler theme. A slow prompt is also felt in every tmux pane and every SSH login.

On a Server: Your User Only

  • No ports: Oh My Zsh opens no network port, so the firewall stays as it is; it only needs outbound HTTPS to GitHub for installs and updates.
  • Leave root alone: keep root's login shell as Bash. Rescue sessions, other administrators, and documentation all expect it.
  • Scripts stay Bash: start shell scripts with #!/bin/bash. Zsh is close to Bash but not the same, for example arrays start at 1, so a script tested in your Zsh prompt may behave differently.
  • Keep your Bash setup: aliases and variables in ~/.bashrc are not read by Zsh. Copy the ones you need into ~/.zshrc; the Bash side is covered in the .bashrc file.

For more on the default shell itself, see what Bash is, and for writing scripts, how to write a Bash script.

Was this answer helpful?
Loading...