# Setting Up Zsh Terminal and Configuring It with Powerlevel10k

### **Step 1: Install Zsh**

1. **Check if Zsh is already installed:**
    
    ```bash
    zsh --version
    ```
    
2. **Install Zsh if it’s not installed:**
    
    * **MacOS** (using Homebrew):
        
        ```bash
        brew install zsh
        ```
        
    * **Ubuntu/Debian:**
        
        ```bash
        sudo apt install zsh -y
        ```
        
    * **Fedora:**
        
        ```bash
        sudo dnf install zsh -y
        ```
        
3. **Set Zsh as the default shell:**
    
    ```bash
    chsh -s $(which zsh)
    ```
    
4. Restart your terminal to use Zsh.
    

---

### **Step 2: Install Oh My Zsh**

Oh My Zsh is a framework for managing your Zsh configuration.

1. **Install Oh My Zsh:**
    
    ```bash
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    ```
    
2. **Verify Installation:** After installation, you’ll notice your terminal prompt changes, indicating Oh My Zsh is active.
    

---

### **Step 3: Install and Configure Powerlevel10k**

Powerlevel10k is a popular theme for Zsh, offering a highly customizable and visually appealing prompt.

1. **Install Powerlevel10k:**
    
    ```bash
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
    ```
    
2. **Set Powerlevel10k as the Theme:** Open your `.zshrc` file:
    
    ```bash
    nano ~/.zshrc
    ```
    
    Update the `ZSH_THEME` line:
    
    ```bash
    ZSH_THEME="powerlevel10k/powerlevel10k"
    ```
    
3. **Apply the Changes:**
    
    ```bash
    source ~/.zshrc
    ```
    
4. **Run Configuration Wizard:** Customize the theme using:
    
    ```bash
    p10k configure
    ```
    

---

### **Step 4: Install Zsh Plugins**

Plugins enhance Zsh by adding helpful functionalities. Here are some essential plugins to install:

1. **Install Plugins:**
    
    * **zsh-autosuggestions:**
        
        ```bash
        git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
        ```
        
    * **zsh-syntax-highlighting:**
        
        ```bash
        git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
        ```
        
2. **Enable Plugins in** `.zshrc`: Add these plugins to the `plugins` array:
    
    ```bash
    plugins=(
      git
      zsh-autosuggestions
      zsh-syntax-highlighting
      jsontools
      history
      dirhistory
      vscode
      docker
      kubectl
      terraform
      aws
      pip
      python
      npm
    )
    ```
    
3. **Apply Changes:**
    
    ```bash
    source ~/.zshrc
    ```
    

---

### **Step 5: Add Custom Paths and Environment Variables**

Customize your `.zshrc` to include paths for tools and frameworks you frequently use:

```bash
# Java
export JAVA_HOME=`/usr/libexec/java_home -v 17`

# Flutter
export PATH="$HOME/development/flutter/bin:$PATH"

# Android SDK
export ANDROID_HOME="$HOME/Library/Android/sdk"
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"

# MySQL
export PATH="/usr/local/mysql-8.0.36-macos14-arm64/bin:$PATH"

# Node.js
export NODE_PATH=$(which node)
```

---

### **Step 6: iTerm2 Integration (Optional)**

If you’re using **iTerm2**, enable shell integration for an enhanced experience:

```bash
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
source ~/.iterm2_shell_integration.zsh
```

---

### **Step 7: Backup and Reload Configurations**

Create shortcuts for backing up and reloading your `.zshrc` file:

```bash
# Backup .zshrc
alias backup-zshrc="cp ~/.zshrc ~/.zshrc.backup && echo 'Backup created at ~/.zshrc.backup'"

# Reload .zshrc
alias update-zsh="source ~/.zshrc && echo 'Reloaded .zshrc settings'"
```

---

### **Step 8: Final Touch - Custom Aliases and Functions**

Create custom aliases or organize them into a directory for easier management:

1. **Add Aliases in** `.zshrc`:
    
    ```bash
    alias ll="ls -lah"
    alias gs="git status"
    alias py="python3"
    ```
    
2. **Load Aliases from Separate Files:**
    
    ```bash
    if [ -d "$HOME/.alias" ]; then
        for file in $HOME/.alias/*; do
            [ -f "$file" ] && source "$file"
        done
    fi
    ```
    

---

### **Step 9: Regular Updates**

Keep Zsh, Oh My Zsh, and plugins up to date:

1. **Update Zsh:**
    
    ```bash
    brew upgrade zsh
    ```
    
2. **Update Oh My Zsh and Plugins:**
    
    ```bash
    omz update
    ```
    

---

### Sample `.zshrc` File

```bash
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
    source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Suppress Powerlevel10k instant prompt warnings
# typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet

# Path to your oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"

# Theme
ZSH_THEME="powerlevel10k/powerlevel10k"

# Enable command auto-correction
ENABLE_CORRECTION="true"

# Display red dots whilst waiting for completion
COMPLETION_WAITING_DOTS="true"

# Plugins
plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
  history
  vscode
  kubectl
)

# Load Oh My Zsh
source $ZSH/oh-my-zsh.sh

# Custom Settings

# Java Home
export JAVA_HOME=$(/usr/libexec/java_home -v 17)

# Vim Keybindings
bindkey -v

# Load Environment Variables from `.env` Directory
if [ -d "$HOME/.env" ] && [ "$(ls -A $HOME/.env)" ]; then
    for file in $HOME/.env/*.env; do
        [ -f "$file" ] && . "$file"
    done
fi

# Load Aliases from `.alias` Directory
if [ -d "$HOME/.alias" ] && [ "$(ls -A $HOME/.alias)" ]; then
    for file in $HOME/.alias/*.sh; do
        [ -f "$file" ] && . "$file"
    done
fi

# Additional Path Updates (already moved to system-paths.env)
export PATH="$PATH"

# Enable NVM (Node Version Manager)
if [ -d "$HOME/.nvm" ]; then
    export NVM_DIR="$HOME/.nvm"
    if [ -s "$NVM_DIR/nvm.sh" ]; then
        source "$NVM_DIR/nvm.sh"
    fi
fi

# iTerm2 Shell Integration
if [ -e "$HOME/.iterm2_shell_integration.zsh" ]; then
    source "$HOME/.iterm2_shell_integration.zsh"
fi

# Backup and Update Aliases
alias backup-zshrc="cp ~/.zshrc ~/.zshrc.backup && echo 'Backup created at ~/.zshrc.backup'"
alias update-zsh="source ~/.zshrc && echo 'Reloaded .zshrc settings'"

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
```

### Organizing Aliases and Environment Variables

To keep your configuration organized, you can separate your aliases and environment variables into dedicated directories:

* **Environment Variables**: Store your environment variables in the `~/.env` directory. Each file should have a `.env` extension and contain the necessary export statements.
    
* **Aliases**: Store your aliases in the `~/.alias` directory. Each file should have a `.sh` extension and contain the alias definitions.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738079099917/0fa92012-cda8-402a-89d2-186d7833abbc.png align="center")
    

This organization helps maintain a clean and manageable `.zshrc` file, making it easier to update and troubleshoot.

### **Conclusion**

With Zsh and Powerlevel10k configured, you now have a powerful terminal setup tailored to your workflow. This setup is highly customizable, so feel free to tweak it further as needed. Happy coding! 🚀
