πŸ‡―πŸ‡΅ ζ—₯本θͺž | πŸ‡ΊπŸ‡Έ English | πŸ‡ͺπŸ‡Έ EspaΓ±ol | πŸ‡΅πŸ‡Ή PortuguΓͺs | πŸ‡ΉπŸ‡­ ΰΉ„ΰΈ—ΰΈ’ | πŸ‡¨πŸ‡³ δΈ­ζ–‡

How to Install Zsh (macOS / Linux) & Initial Setup Guide

In our previous article, "What is Zsh? Why Developers Love It and How It Differs from Bash," we introduced just how powerful and appealing the Zsh shell is. After learning about its smart completion features and numerous handy shortcuts, many of you are probably thinking, "I want to start using Zsh as my main shell!"

This article will walk you through the concrete steps to install Zsh on your machine and take the first step toward building a comfortable command-line environment. We'll cover everything from the installation methods for macOS and Linux (Ubuntu/Debian-based) to the initial setup you should perform when you first launch Zsh, and the basics of its configuration file, which is your gateway to customization.

By the end of this article, you'll have a solid foundation for mastering Zsh as your main shell. Let's begin the journey to building the ultimate shell environment!


1. Installing Zsh

First, let's install Zsh on your operating system. While modern versions of macOS already come with Zsh as the default, we'll review the installation method for Linux environments or for those who want to use a newer version of Zsh.

For macOS

Since macOS Catalina, Zsh comes pre-installed as the default shell. Let's start by checking its version.

$ zsh --version
zsh 5.8 (x86_64-apple-darwin21.0)

If you want to use a newer version, you can easily install it using Homebrew.


brew install zsh

For Linux (Ubuntu/Debian-based)

In many Linux distributions, Zsh is not installed by default. However, you can install it with a single line using a package manager.

First, update your package list to the latest state.

sudo apt update

Next, install zsh.

sudo apt install -y zsh

Changing the Login Shell to Zsh

Just installing Zsh isn't enough; it won't automatically become your shell when you open a new terminal. You need to change your login shell (the shell used when the terminal starts) to Zsh. Let's use the chsh command.

chsh -s $(which zsh)

The $(which zsh) part automatically finds the path where zsh is installed. After running the command, enter your password if prompted, and restart your terminal for the changes to take effect.


2. The Zsh Initial Configuration Wizard

The first time you launch Zsh, the following message will appear, and the initial configuration wizard will start.

This is the Z Shell configuration function for new users, zsh-newuser-install.
You are seeing this message because you have no zsh startup files...
---
Please pick one of the following options:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function from being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit.

It's important to understand what each option means here.

For beginners, pressing the 2 key to start with the recommended settings is the easiest and most reliable option.


3. Understanding the ".zshrc" Configuration File

When you select 2 in the initial setup wizard, a file named .zshrc is created in your home directory (~/). This is the main configuration file for Zsh, equivalent to .bashrc in Bash. The settings written in this file are loaded every time you open a new terminal.

Let's take a peek at its contents with the cat command.

$ cat ~/.zshrc
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory autocd extendedglob nomatch
# End of lines configured by zsh-newuser-install
# ...

You can see that useful options like history settings and the autocd feature (directory navigation without `cd`) we mentioned earlier are already enabled. To customize Zsh further, you will be editing this .zshrc file.


4. Simple Customization Example: Aliases

Now that you understand how .zshrc works, let's try a simple customization.

Registering an Alias

Let's assign a short alias to a long, frequently used command. Here, we'll create an alias ll for ls -alF (detailed list view). We'll use the echo command to append the setting to the end of the .zshrc file.

echo "alias ll='ls -alF'" >> ~/.zshrc

To apply the setting, either run the following command or reopen your terminal.

source ~/.zshrc

Now, simply typing ll will execute ls -alF.

$ ll

Summary

Great job! In this guide, we covered everything from installing Zsh to navigating the initial setup wizard and performing simple customizations using .zshrc.

Your Zsh environment is now ready for customization. However, the true power of Zsh blossoms when you use a framework like "Oh My Zsh," which makes it easy to install plugins and themes created by developers worldwide.

In the next article, we'll finally install Oh My Zsh and show you how to dramatically transform your terminal into a more convenient and stylish tool. Stay tuned!

How to Supercharge Your Zsh with Oh My Zsh [Themes & Plugins]