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.
1sudo apt update && sudo apt install -y zshAfter installation, verify the Zsh version and installation path:
1# Check Zsh version2zsh --version3
4# Verify installation path5which zsh6
7# Expected output: /usr/bin/zsh or /bin/zshTechnical 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.
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:
1sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"For manual installation (greater control over the process):
1# Clone the Oh My Zsh repository2git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh3
4# Create a new Zsh configuration file from the template5cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrcWhat the installer does:
- Clones the Oh My Zsh repository to
~/.oh-my-zsh - Backs up existing
~/.zshrcto~/.zshrc.pre-oh-my-zsh - Creates a new
~/.zshrcfrom the template - Changes the default shell to Zsh (may prompt for password)
Understanding Oh My Zsh Directory Structure
1~/.oh-my-zsh/2├── custom/ # Custom plugins, themes, and configuration3│ ├── plugins/ # User-installed plugins4│ └── themes/ # User-installed themes5├── lib/ # Core Oh My Zsh library functions6├── plugins/ # Built-in plugins (300+)7├── themes/ # Built-in themes (140+)8└── tools/ # Maintenance and update scriptsInstall 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.
1git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10kFont Installation (Recommended)
Powerlevel10k requires a Nerd Font for proper icon rendering. Install MesloLGS NF (recommended font):
1# Create fonts directory if it doesn't exist2mkdir -p ~/.local/share/fonts3
4# Download MesloLGS NF fonts5cd ~/.local/share/fonts6wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf7wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf8wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf9wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf10
11# Refresh font cache12fc-cache -fv13
14# Verify font installation15fc-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:
1sed -i 's/ZSH_THEME=".\*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrcManual alternative (if you prefer to edit the file directly):
1# Open .zshrc in your preferred editor2nano ~/.zshrc3
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-themefile 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:
1chsh -s $(which zsh)Verification and troubleshooting:
1# Verify which shell will be used on next login2echo $SHELL3
4# Check the entry in /etc/passwd5grep $USER /etc/passwd6
7# Expected output: username:x:1000:1000:,,,:/home/username:/usr/bin/zshImportant notes:
- You may need to enter your password when running
chsh - The change takes effect on the next login (new terminal session)
- If
chshis not available, you can edit/etc/passwddirectly with sudo (not recommended) - Some systems require Zsh to be listed in
/etc/shells:
1# Verify Zsh is listed in allowed shells2cat /etc/shells3
4# If Zsh is missing, add it (requires sudo)5echo $(which zsh) | sudo tee -a /etc/shellsRun setup wizard
Run setup wizard
Start a new Zsh session to trigger the Powerlevel10k configuration wizard:
1exec zshWhat 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:
- Prompt Style: Choose between lean, classic, rainbow, or pure styles
- Character Set: Unicode or ASCII characters
- Prompt Colors: 256 colors, true color, or 8 colors
- Show Current Time: 12-hour, 24-hour, or disabled
- Prompt Separators: Angled, straight, rounded, or slanted
- Prompt Heads: Sharp, blurred, or flat
- Prompt Tails: Flat, blurred, sharp, or slanted
- Prompt Height: One line or two lines
- Prompt Connection: Disconnected, dotted, or solid
- Prompt Frame: No frame, left, or full
- Prompt Spacing: Compact, sparse, or normal
- Icons: Many icons or few icons
- Prompt Flow: Concise or fluent
- Enable Transient Prompt: Yes or no
- Instant Prompt Mode: Verbose, quiet, or off
The configuration is saved to ~/.p10k.zsh. You can reconfigure anytime:
1p10k configureEdit 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:
1nano ~/.zshrc2# Add the following line at the end of the file3
4setopt globdotsUnderstanding Zsh shell options:
The setopt command enables shell options in Zsh. Here are other useful options to consider:
1# Auto-cd: Change directory without typing 'cd'2setopt autocd3
4# Correction: Suggest corrections for mistyped commands5setopt correct6
7# Append history: Immediately append to history file8setopt appendhistory9
10# Share history: Share history between all sessions11setopt sharehistory12
13# Extended history: Save timestamp and duration14setopt extendedhistory15
16# History ignore dups: Don't record duplicate commands17setopt histignoredups18
19# Case-insensitive globbing20setopt nocaseglob21
22# Notify immediately when background jobs finish23setopt notify24
25# Don't beep on error26unsetopt beepAdd these options to your ~/.zshrc file for enhanced functionality.
Additional Configuration
Recommended Oh My Zsh Plugins
Oh My Zsh comes with many useful plugins. Add them to the plugins array in ~/.zshrc:
1plugins=(2 git # Git aliases and functions3 sudo # Press ESC twice to add sudo to command4 web-search # Search from terminal (google, bing, etc.)5 jsontools # JSON manipulation tools6 docker # Docker command completion7 docker-compose # Docker Compose completion8 kubectl # Kubernetes completion9 history # History aliases10 colored-man-pages # Colorized man pages11 command-not-found # Suggests packages for missing commands12 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):
1git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestionszsh-syntax-highlighting (highlights commands in real-time):
1git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlightingAfter installing, add them to the plugins array and reload:
1source ~/.zshrcCustom Aliases
Add useful aliases to ~/.zshrc or ~/.oh-my-zsh/custom/aliases.zsh:
1# System updates2alias update='sudo apt update && sudo apt upgrade -y'3alias autoremove='sudo apt autoremove -y'4
5# Navigation6alias ..='cd ..'7alias ...='cd ../..'8alias ....='cd ../../..'9
10# List files with details11alias ll='ls -lAh'12alias la='ls -A'13alias l='ls -CF'14
15# Disk usage16alias du='du -h'17alias df='df -h'18
19# Safety nets20alias rm='rm -i'21alias cp='cp -i'22alias mv='mv -i'23
24# Process management25alias 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# Network30alias ports='netstat -tulanp'31alias myip='curl ifconfig.me'32
33# Git shortcuts34alias 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 shortcuts41alias 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:
1# History file location2HISTFILE=~/.zsh_history3
4# Number of commands to save in memory5HISTSIZE=100006
7# Number of commands to save in history file8SAVEHIST=100009
10# Additional history options11setopt EXTENDED_HISTORY # Write timestamp to history file12setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first13setopt HIST_IGNORE_DUPS # Don't record duplicate consecutive entries14setopt HIST_IGNORE_ALL_DUPS # Delete old duplicate entries15setopt HIST_FIND_NO_DUPS # Don't display duplicates in search16setopt HIST_IGNORE_SPACE # Don't record entries starting with space17setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries18setopt HIST_REDUCE_BLANKS # Remove superfluous blanks19setopt SHARE_HISTORY # Share history between sessionsEnvironment Variables
Set useful environment variables in ~/.zshrc:
1# Default editor2export EDITOR='nano'3export VISUAL='nano'4
5# Less configuration (better paging)6export LESS='-R -M -i'7
8# Colorized less output9export LESS_TERMCAP_mb=$'\E[1;31m' # begin bold10export LESS_TERMCAP_md=$'\E[1;36m' # begin blink11export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink12export LESS_TERMCAP_so=$'\E[01;44;33m' # begin reverse video13export LESS_TERMCAP_se=$'\E[0m' # reset reverse video14export LESS_TERMCAP_us=$'\E[1;32m' # begin underline15export LESS_TERMCAP_ue=$'\E[0m' # reset underline16
17# Add local bin to PATH18export PATH="$HOME/.local/bin:$PATH"19
20# Language settings21export LANG=en_US.UTF-822export LC_ALL=en_US.UTF-8Maintenance and Updates
Updating Oh My Zsh
Oh My Zsh includes an automatic update mechanism that checks for updates every 2 weeks:
1# Manual update2omz update3
4# Update all: Oh My Zsh + plugins + themes5cd ~/.oh-my-zsh && git pull6cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions && git pull7cd ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting && git pull8cd ~/.oh-my-zsh/custom/themes/powerlevel10k && git pullUpdating Powerlevel10k
1git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k pullPerformance Profiling
If Zsh startup feels slow, profile it:
1# Add this to the top of ~/.zshrc2zmodload zsh/zprof3
4# Add this to the bottom of ~/.zshrc5zprofThen restart Zsh to see timing information for each section.
Troubleshooting
Slow startup with Powerlevel10k:
Check if instant prompt is enabled in ~/.p10k.zsh:
1# Enable instant prompt (should be at the top of .zshrc)2if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then3 source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"4fiBroken icons/glyphs:
Ensure your terminal is using a Nerd Font (MesloLGS NF recommended).
Plugin conflicts:
Disable plugins one by one to identify conflicts:
1# Temporarily disable all plugins2plugins=()Reset to defaults:
1# Backup current config2cp ~/.zshrc ~/.zshrc.backup3
4# Restore default Oh My Zsh config5cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc6
7# Reconfigure Powerlevel10k8p10k configureConclusion
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:
- Explore the Oh My Zsh plugins directory
- Customize your
~/.p10k.zshconfiguration - Add your own aliases and functions to
~/.zshrc - Join the community: r/zsh, Oh My Zsh discussions
Useful commands reference:
| Command | Description |
|---|---|
omz update | Update Oh My Zsh |
omz reload | Reload Zsh configuration |
p10k configure | Reconfigure Powerlevel10k |
source ~/.zshrc | Apply configuration changes |
echo $ZSH_VERSION | Check Zsh version |
which zsh | Find Zsh binary location |
printenv | Display environment variables |
alias | List all aliases |
setopt | List enabled shell options |