🚀 A hands-on guide to setting up zsh, oh my zsh, asdf, and spaceship prompt with zinit for your development environment
Tags: terminal, zsh, tutorial, beginners
Published: 2024-06-18 13:20:56

## **Introduction** 🌟

Elevate your development environment with this guide on installing and configuring **Zsh**, **Oh My Zsh**, **asdf**, and the **Spaceship Prompt** theme. We will also leverage **Zinit** for additional plugin management. Let’s get started!

🚨🚨🚨 **WARNING:If you like it this article please click in reaction and save, also follow me here and on my [Github](https://github.com/girordo)**

### 🛠️ **Step 1: Installing Zsh**

**Zsh** is a robust shell that provides a powerful command-line experience. Here’s how to install it:

#### 🐧 **For Linux (Ubuntu/Debian):**

```bash
sudo apt update
sudo apt install zsh
chsh -s $(which zsh)
```

#### 🍎 **For macOS:**

Zsh is pre-installed. To set it as your default shell:

```bash
chsh -s /bin/zsh
```

#### 🪟 **For Windows:**

Use **WSL (Windows Subsystem for Linux)** or **Git Bash**. For WSL:

1. Install a WSL distribution (e.g., Ubuntu) from the Microsoft Store.
2. Install Zsh as you would on Ubuntu.

**Verify the installation**:

```bash
zsh --version
```

### ⚙️ **Step 2: Setting Up Oh My Zsh**

**Oh My Zsh** simplifies Zsh configuration with themes and plugins.

**Install Oh My Zsh**:

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

This script will set up Oh My Zsh and switch your default shell to Zsh.

**Configure Oh My Zsh**:

1. Open your `.zshrc` file:

    ```bash
    nano ~/.zshrc
    ```

2. **Enable plugins**:

    ```bash
    plugins=(git asdf)
    ```

3. **Reload your configuration**:

    ```bash
    source ~/.zshrc
    ```

### 🔄 **Step 3: Installing and Configuring Zinit**

**Zinit** is a plugin manager for Zsh, offering flexible and fast plugin management.

**Install Zinit**:

1. Add Zinit installer chunk to your `.zshrc`:

    ```bash
    cat << 'EOF' >> ~/.zshrc

    ### Added by Zinit's installer
    if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
        print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
        command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
        command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
            print -P "%F{33} %F{34}Installation successful.%f%b" || \
            print -P "%F{160} The clone has failed.%f%b"
    fi

    source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
    autoload -Uz _zinit
    (( ${+_comps} )) && _comps[zinit]=_zinit

    # Load a few important annexes, without Turbo
    zinit light-mode for \
        zdharma-continuum/zinit-annex-as-monitor \
        zdharma-continuum/zinit-annex-bin-gem-node \
        zdharma-continuum/zinit-annex-patch-dl \
        zdharma-continuum/zinit-annex-rust

    ### End of Zinit's installer chunk

    EOF
    ```

2. **Source your `.zshrc`**:

    ```bash
    source ~/.zshrc
    ```

### 🔌 **Step 4: Installing Additional Plugins with Zinit**

Use Zinit to install additional plugins for a richer Zsh experience.

**Install plugins using Zinit**:

1. Open your `.zshrc` file and add the following Zinit plugin commands:

    ```bash
    nano ~/.zshrc
    ```

2. Add these lines to install and load additional plugins:

    ```bash
    zinit light zdharma-continuum/fast-syntax-highlighting
    zinit light zsh-users/zsh-autosuggestions
    zinit light zsh-users/zsh-completions
    ```

3. **Save and reload** your `.zshrc`:

    ```bash
    source ~/.zshrc
    ```

### 📦 **Step 5: Installing and Configuring asdf**

**asdf** is a versatile version manager for multiple languages.

**Install asdf**:

1. Clone the asdf repository:

    ```bash
    git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
    ```

2. Add asdf to your `.zshrc`:

    ```bash
    echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.zshrc
    echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc
    source ~/.zshrc
    ```

**Install asdf plugins**:

1. **Add the Node.js plugin**:

    ```bash
    asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git
    ```

2. **Install a specific version**:

    ```bash
    asdf install nodejs 16.13.0
    asdf global nodejs 16.13.0
    ```

3. **Add the Python plugin**:

    ```bash
    asdf plugin-add python https://github.com/danhper/asdf-python.git
    ```

4. **Install a specific version**:

    ```bash
    asdf install python 3.9.7
    asdf global python 3.9.7
    ```

**Managing project-specific versions**:

Create a `.tool-versions` file in your project directory:

```bash
nodejs 14.17.6
python 3.8.10
```

Run `asdf install` in the project directory to use these versions locally.

### 🚀 **Step 6: Configuring the Spaceship Prompt Theme**

The **Spaceship Prompt** theme offers a sleek and informative prompt for Zsh.

**Install Spaceship Prompt**:

1. **Clone the Spaceship repository**:

    ```bash
    git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1
    ```

2. **Create a symlink**:

    ```bash
    ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
    ```

3. **Set the theme in your `.zshrc`**:

    ```bash
    ZSH_THEME="spaceship"
    ```

**Configure Spaceship Prompt**:

1. Create a configuration file `.spaceshiprc.zsh`:

    ```bash
    nano ~/.spaceshiprc.zsh
    ```

2. Add the following configuration:

    ```zsh
    SPACESHIP_USER_SHOW=always
    SPACESHIP_PROMPT_ADD_NEWLINE=false
    SPACESHIP_CHAR_SYMBOL="λ"
    SPACESHIP_CHAR_SUFFIX=" "
    SPACESHIP_PROMPT_ORDER=(
      user          # Username section
      dir           # Current directory section
      host          # Hostname section
      git           # Git section (git_branch + git_status)
      package       # Package version
      node          # Node.js section
      bun           # Bun section
      elixir        # Elixir section
      erlang        # Erlang section
      rust          # Rust section
      docker        # Docker section
      docker_compose # Docker Compose section
      terraform     # Terraform section
      exec_time     # Execution time
      line_sep      # Line break
      jobs          # Background jobs indicator
      exit_code     # Exit code section
      char          # Prompt character
    )
    ```

3. **Source your configuration** in `.zshrc`:

    ```bash
    echo "source ~/.spaceshiprc.zsh" >> ~/.zshrc
    source ~/.zshrc
    ```

**Enable Command History Sharing**:

To share command history across sessions:

```bash
HISTFILE=

~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt share_history
```

**Enable Auto-Corrections**:

Enable corrections for common typos:

```bash
setopt correct
```

### 🔠 **Step 7: Adding a Nerd Font for the Spaceship Prompt**

**Nerd Fonts** provide additional icons and glyphs that enhance the appearance of your terminal, especially with themes like Spaceship Prompt.

1. **Install a Nerd Font** (e.g., Hack or Roboto Mono):

   - Go to the [Nerd Fonts GitHub repository](https://github.com/ryanoasis/nerd-fonts) and download your preferred font (e.g., Hack or Roboto Mono).
   - Follow the installation instructions for your operating system.

2. **Configure Your Terminal Emulator**:

   - Open your terminal emulator's preferences/settings.
   - Select the installed Nerd Font (e.g., Hack Nerd Font or Roboto Mono Nerd Font) as the font for your terminal.

Now, your Spaceship Prompt should display with the Nerd Font icon you selected.

### 🎉 **Conclusion**

You’ve now set up a robust and visually appealing development environment with **Zsh**, **Oh My Zsh**, **asdf**, and the **Spaceship Prompt** theme, using **Zinit** for additional plugins. This configuration will enhance your workflow and make managing multiple projects a breeze. Happy coding!

---

**Further Reading** 📚:

- [Oh My Zsh Plugins](https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins)
- [asdf Documentation](https://asdf-vm.com/)
- [Spaceship Prompt GitHub](https://github.com/spaceship-prompt/spaceship-prompt)
- [Zinit Documentation](https://zdharma-continuum.github.io/zinit/wiki/)
- [Zsh User Guide](http://zsh.sourceforge.net/Doc/Release/)

---
Photo by <a href="https://unsplash.com/@lukash?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Lukas</a> on <a href="https://unsplash.com/photos/a-computer-screen-with-a-lot-of-data-on-it-MU8w72PzRow?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>

<p align="center"><em>This article was crafted and tailored with ChatGPT help.</em> 🤖💡</p>