Top Tags

Install Zsh, p10k, Oh My Zsh on Ubuntu

A step-by-step guide to installing Zsh, Powerlevel10k theme, and Oh My Zsh framework on Ubuntu.

Introduction

Zsh (Z Shell) is an advanced Unix shell that extends the functionality of the Bourne Shell (sh) with numerous improvements. It provides powerful features like:

  • Advanced tab completion: Context-aware completion with descriptions
  • Globbing enhancements: Extended pattern matching capabilities
  • Spelling correction: Automatic command and path correction
  • Themeable prompts: Highly customizable prompt system
  • Shared command history: History shared across multiple terminal sessions
  • Plugin architecture: Extensible through plugins and frameworks

Oh My Zsh is a community-driven framework for managing Zsh configuration, providing 300+ plugins and 140+ themes out of the box.

Powerlevel10k is a fast, flexible, and feature-rich Zsh theme that emphasizes speed and flexibility with instant prompt rendering.

System Requirements

  • Ubuntu 18.04 LTS or newer
  • Git (for cloning repositories)
  • curl or wget (for downloading installation scripts)
  • sudo privileges (for installing system packages)

Install Zsh

Zsh is available in the official Ubuntu repositories. The installation also includes Zsh documentation and default configuration files.

bash
1sudo apt update && sudo apt install -y zsh

After installation, verify the Zsh version and installation path:

bash
1# Check Zsh version
2zsh --version
3
4# Verify installation path
5which zsh
6
7# Expected output: /usr/bin/zsh or /bin/zsh

Technical Note: The package installs Zsh binaries, man pages, and default configuration templates. The default system-wide configuration is located at /etc/zsh/, while user-specific configuration will be stored in ~/.zshrc after initialization.

Install Oh My Zsh

Install Oh My Zsh

Oh My Zsh is installed via an automated installation script that clones the repository and sets up the initial configuration.

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

Alternative installation methods:

If you prefer using wget instead of curl:

bash
1sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

For manual installation (greater control over the process):

bash
1# Clone the Oh My Zsh repository
2git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
3
4# Create a new Zsh configuration file from the template
5cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

What the installer does:

  1. Clones the Oh My Zsh repository to ~/.oh-my-zsh
  2. Backs up existing ~/.zshrc to ~/.zshrc.pre-oh-my-zsh
  3. Creates a new ~/.zshrc from the template
  4. Changes the default shell to Zsh (may prompt for password)

Understanding Oh My Zsh Directory Structure

plaintext
1~/.oh-my-zsh/
2├── custom/ # Custom plugins, themes, and configuration
3│ ├── plugins/ # User-installed plugins
4│ └── themes/ # User-installed themes
5├── lib/ # Core Oh My Zsh library functions
6├── plugins/ # Built-in plugins (300+)
7├── themes/ # Built-in themes (140+)
8└── tools/ # Maintenance and update scripts

Install Powerlevel10k

Install Powerlevel10k

Powerlevel10k is installed as a custom Oh My Zsh theme. The --depth=1 flag creates a shallow clone, downloading only the latest commit to save bandwidth and disk space.

bash
1git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Powerlevel10k requires a Nerd Font for proper icon rendering. Install MesloLGS NF (recommended font):

bash
1# Create fonts directory if it doesn't exist
2mkdir -p ~/.local/share/fonts
3
4# Download MesloLGS NF fonts
5cd ~/.local/share/fonts
6wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
7wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
8wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
9wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
10
11# Refresh font cache
12fc-cache -fv
13
14# Verify font installation
15fc-list | grep "MesloLGS NF"

After installing fonts, configure your terminal emulator to use "MesloLGS NF" as the font.

Performance characteristics:

  • Instant prompt: Renders prompt immediately, before Zsh fully loads
  • Asynchronous rendering: Git status and other elements load without blocking
  • Optimized for speed: 10-100x faster than Powerlevel9k
  • Transient prompt: Keeps command history clean and readable

Set theme in .zshrc

Set theme in .zshrc

Update the ZSH_THEME variable in your .zshrc configuration file to use Powerlevel10k:

bash
1sed -i 's/ZSH_THEME=".\*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc

Manual alternative (if you prefer to edit the file directly):

bash
1# Open .zshrc in your preferred editor
2nano ~/.zshrc
3
4# Find the line that starts with ZSH_THEME= and change it to:
5# ZSH_THEME="powerlevel10k/powerlevel10k"

Understanding the theme path: The path powerlevel10k/powerlevel10k refers to:

  • First powerlevel10k: Directory name in ~/.oh-my-zsh/custom/themes/
  • Second powerlevel10k: The .zsh-theme file name

Change default shell to Zsh

Change default shell to Zsh

The chsh command modifies the /etc/passwd file to set your default login shell:

bash
1chsh -s $(which zsh)

Verification and troubleshooting:

bash
1# Verify which shell will be used on next login
2echo $SHELL
3
4# Check the entry in /etc/passwd
5grep $USER /etc/passwd
6
7# Expected output: username:x:1000:1000:,,,:/home/username:/usr/bin/zsh

Important notes:

  • You may need to enter your password when running chsh
  • The change takes effect on the next login (new terminal session)
  • If chsh is not available, you can edit /etc/passwd directly with sudo (not recommended)
  • Some systems require Zsh to be listed in /etc/shells:
bash
1# Verify Zsh is listed in allowed shells
2cat /etc/shells
3
4# If Zsh is missing, add it (requires sudo)
5echo $(which zsh) | sudo tee -a /etc/shells

Run setup wizard

Run setup wizard

Start a new Zsh session to trigger the Powerlevel10k configuration wizard:

bash
1exec zsh

What exec zsh does:

  • Replaces the current shell process with Zsh
  • Does not create a subshell (more efficient than just running zsh)
  • Triggers Powerlevel10k configuration wizard on first run

Configuration Wizard Options

The wizard will ask several questions to customize your prompt:

  1. Prompt Style: Choose between lean, classic, rainbow, or pure styles
  2. Character Set: Unicode or ASCII characters
  3. Prompt Colors: 256 colors, true color, or 8 colors
  4. Show Current Time: 12-hour, 24-hour, or disabled
  5. Prompt Separators: Angled, straight, rounded, or slanted
  6. Prompt Heads: Sharp, blurred, or flat
  7. Prompt Tails: Flat, blurred, sharp, or slanted
  8. Prompt Height: One line or two lines
  9. Prompt Connection: Disconnected, dotted, or solid
  10. Prompt Frame: No frame, left, or full
  11. Prompt Spacing: Compact, sparse, or normal
  12. Icons: Many icons or few icons
  13. Prompt Flow: Concise or fluent
  14. Enable Transient Prompt: Yes or no
  15. Instant Prompt Mode: Verbose, quiet, or off

The configuration is saved to ~/.p10k.zsh. You can reconfigure anytime:

bash
1p10k configure

Edit config Zsh to view dot files

Edit config Zsh to view dot files

Enable the globdots option to include hidden files (dotfiles) in glob patterns:

bash
1nano ~/.zshrc
2# Add the following line at the end of the file
3
4setopt globdots

Understanding Zsh shell options:

The setopt command enables shell options in Zsh. Here are other useful options to consider:

bash
1# Auto-cd: Change directory without typing 'cd'
2setopt autocd
3
4# Correction: Suggest corrections for mistyped commands
5setopt correct
6
7# Append history: Immediately append to history file
8setopt appendhistory
9
10# Share history: Share history between all sessions
11setopt sharehistory
12
13# Extended history: Save timestamp and duration
14setopt extendedhistory
15
16# History ignore dups: Don't record duplicate commands
17setopt histignoredups
18
19# Case-insensitive globbing
20setopt nocaseglob
21
22# Notify immediately when background jobs finish
23setopt notify
24
25# Don't beep on error
26unsetopt beep

Add these options to your ~/.zshrc file for enhanced functionality.

Additional Configuration

Oh My Zsh comes with many useful plugins. Add them to the plugins array in ~/.zshrc:

bash
1plugins=(
2 git # Git aliases and functions
3 sudo # Press ESC twice to add sudo to command
4 web-search # Search from terminal (google, bing, etc.)
5 jsontools # JSON manipulation tools
6 docker # Docker command completion
7 docker-compose # Docker Compose completion
8 kubectl # Kubernetes completion
9 history # History aliases
10 colored-man-pages # Colorized man pages
11 command-not-found # Suggests packages for missing commands
12 zsh-autosuggestions # Fish-like autosuggestions (requires installation)
13 zsh-syntax-highlighting # Fish-like syntax highlighting (requires installation)
14)

Installing Additional Plugin Dependencies

Some popular plugins need to be installed separately:

zsh-autosuggestions (suggests commands as you type based on history):

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

zsh-syntax-highlighting (highlights commands in real-time):

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

After installing, add them to the plugins array and reload:

bash
1source ~/.zshrc

Custom Aliases

Add useful aliases to ~/.zshrc or ~/.oh-my-zsh/custom/aliases.zsh:

bash
1# System updates
2alias update='sudo apt update && sudo apt upgrade -y'
3alias autoremove='sudo apt autoremove -y'
4
5# Navigation
6alias ..='cd ..'
7alias ...='cd ../..'
8alias ....='cd ../../..'
9
10# List files with details
11alias ll='ls -lAh'
12alias la='ls -A'
13alias l='ls -CF'
14
15# Disk usage
16alias du='du -h'
17alias df='df -h'
18
19# Safety nets
20alias rm='rm -i'
21alias cp='cp -i'
22alias mv='mv -i'
23
24# Process management
25alias psg='ps aux | grep -v grep | grep -i -e VSZ -e'
26alias psmem='ps auxf | sort -nr -k 4 | head -10'
27alias pscpu='ps auxf | sort -nr -k 3 | head -10'
28
29# Network
30alias ports='netstat -tulanp'
31alias myip='curl ifconfig.me'
32
33# Git shortcuts
34alias gs='git status'
35alias ga='git add'
36alias gc='git commit'
37alias gp='git push'
38alias gl='git log --oneline --decorate --graph'
39
40# Docker shortcuts
41alias dps='docker ps'
42alias dpa='docker ps -a'
43alias di='docker images'
44alias dstop='docker stop $(docker ps -aq)'
45alias drm='docker rm $(docker ps -aq)'

History Configuration

Optimize history settings in ~/.zshrc:

bash
1# History file location
2HISTFILE=~/.zsh_history
3
4# Number of commands to save in memory
5HISTSIZE=10000
6
7# Number of commands to save in history file
8SAVEHIST=10000
9
10# Additional history options
11setopt EXTENDED_HISTORY # Write timestamp to history file
12setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first
13setopt HIST_IGNORE_DUPS # Don't record duplicate consecutive entries
14setopt HIST_IGNORE_ALL_DUPS # Delete old duplicate entries
15setopt HIST_FIND_NO_DUPS # Don't display duplicates in search
16setopt HIST_IGNORE_SPACE # Don't record entries starting with space
17setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries
18setopt HIST_REDUCE_BLANKS # Remove superfluous blanks
19setopt SHARE_HISTORY # Share history between sessions

Environment Variables

Set useful environment variables in ~/.zshrc:

bash
1# Default editor
2export EDITOR='nano'
3export VISUAL='nano'
4
5# Less configuration (better paging)
6export LESS='-R -M -i'
7
8# Colorized less output
9export LESS_TERMCAP_mb=$'\E[1;31m' # begin bold
10export LESS_TERMCAP_md=$'\E[1;36m' # begin blink
11export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink
12export LESS_TERMCAP_so=$'\E[01;44;33m' # begin reverse video
13export LESS_TERMCAP_se=$'\E[0m' # reset reverse video
14export LESS_TERMCAP_us=$'\E[1;32m' # begin underline
15export LESS_TERMCAP_ue=$'\E[0m' # reset underline
16
17# Add local bin to PATH
18export PATH="$HOME/.local/bin:$PATH"
19
20# Language settings
21export LANG=en_US.UTF-8
22export LC_ALL=en_US.UTF-8

Maintenance and Updates

Updating Oh My Zsh

Oh My Zsh includes an automatic update mechanism that checks for updates every 2 weeks:

bash
1# Manual update
2omz update
3
4# Update all: Oh My Zsh + plugins + themes
5cd ~/.oh-my-zsh && git pull
6cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions && git pull
7cd ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting && git pull
8cd ~/.oh-my-zsh/custom/themes/powerlevel10k && git pull

Updating Powerlevel10k

bash
1git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k pull

Performance Profiling

If Zsh startup feels slow, profile it:

bash
1# Add this to the top of ~/.zshrc
2zmodload zsh/zprof
3
4# Add this to the bottom of ~/.zshrc
5zprof

Then restart Zsh to see timing information for each section.

Troubleshooting

Slow startup with Powerlevel10k:

Check if instant prompt is enabled in ~/.p10k.zsh:

bash
1# Enable instant prompt (should be at the top of .zshrc)
2if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
3 source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
4fi

Broken icons/glyphs:

Ensure your terminal is using a Nerd Font (MesloLGS NF recommended).

Plugin conflicts:

Disable plugins one by one to identify conflicts:

bash
1# Temporarily disable all plugins
2plugins=()

Reset to defaults:

bash
1# Backup current config
2cp ~/.zshrc ~/.zshrc.backup
3
4# Restore default Oh My Zsh config
5cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
6
7# Reconfigure Powerlevel10k
8p10k configure

Conclusion

You now have a fully configured Zsh environment with:

  • ✅ Zsh as your default shell
  • ✅ Oh My Zsh framework for extensibility
  • ✅ Powerlevel10k theme for a beautiful, fast prompt
  • ✅ Recommended plugins and configurations
  • ✅ Custom aliases and environment variables

Next steps:

  1. Explore the Oh My Zsh plugins directory
  2. Customize your ~/.p10k.zsh configuration
  3. Add your own aliases and functions to ~/.zshrc
  4. Join the community: r/zsh, Oh My Zsh discussions

Useful commands reference:

CommandDescription
omz updateUpdate Oh My Zsh
omz reloadReload Zsh configuration
p10k configureReconfigure Powerlevel10k
source ~/.zshrcApply configuration changes
echo $ZSH_VERSIONCheck Zsh version
which zshFind Zsh binary location
printenvDisplay environment variables
aliasList all aliases
setoptList enabled shell options