Setup Zsh As Your Default Shell
Tags: webdev, beginners, tutorial, tooling
Published: 2021-11-21 15:10:56

---
title: 'Setup Zsh As Your Default Shell'
publishedAt: '2021-11-03'
summary: Switching from Bash to Zsh? Getting your terminal on board can be tricky. In this post, I'll show you how to setup Zsh as your default shell.
tags: ['webdev', 'beginners', 'tutorial', 'tooling']
published: true
canonical_url: https://jakewiesler.com/blog/zsh-as-default-shell
---

If you're switching from Bash to Zsh and you want to know how to launch new terminal sessions _in Zsh_, you've found the right blog post. I've had to do this a few times over the years, and it was always a struggle. Recently [I started working on a portable development environment](https://www.youtube.com/playlist?list=PL1C97G3GhlHdANMFUIXTcFr14R7b7EBj9) and I learned how to set Zsh as my default shell _the right way_. Here's how:

## Prerequisite: Install Zsh

How you install Zsh is up to you. Checkout [this GitHub gist](https://gist.github.com/derhuerst/12a1558a4b408b3b2b6e) for some OS-specific options. The following steps will work for any Linux/Unix-based machine. I am not aware of how to accomplish this on Windows.

## Step 1

The first step is to tell your terminal that Zsh can be used as a valid login shell. You do this by updating a special file named `/etc/shells`. If you `cat` this file:

```shell
cat /etc/shells
```

You will see a list of filepaths that each point to an executable file.

```markup
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
```

The output above may vary depending on your circumstance. One of these executables is your current shell. You can see your current shell by running:

```shell
echo $SHELL
```

The output of the command above will be an executable file that resides within the `/etc/shells` list. For example, if I run the `echo` command above, the output I see is:

```markup
/bin/bash
```

### Locate Zsh's executable filepath

We need to append the Zsh exectuable to this list, but before doing that we need to know where it is. To find its location you can run the following command:

```shell
command -v zsh
```

`command -v` will print the absolute filepath used when invoking the argument provided, in this case `zsh`. This gives us the path to Zsh's exectuable file. The location may vary depending on your installation method.

For example, running the command above may yield:

```markup
/bin/zsh
```

If you see no output at all, then you probably don't have Zsh installed. See [Prerequisites](#prerequisite-install-zsh).

### Append Zsh's executable filepath to `/etc/shells`

Once we have the location of Zsh's exectuable file, we can "pipe" it to another command:

```shell
sudo tee -a /etc/shells
```

The `tee` utility, which we are running in `sudo`, takes an input and appends it to `/etc/shells`.

Together, the full command is:

```shell
command -v zsh | sudo tee -a /etc/shells
```

The `|` is the pipe symbol. It takes the output of the left-hand side and uses it as the input for the right-hand side. In psuedo, what's happening is:

1. Locate the filepath of Zsh
2. Append the filepath to `/etc/shells`

After running the full command you should see Zsh's executable at the bottom of `/etc/shells`.

## Step 2

Now that we've told our terminal that Zsh can be used as a valid login shell, we need to explicitly use it as _the default_. This can be accomplished with the following command:

```shell
sudo chsh -s $(which zsh) $USER
```

The command above is `chsh -s`, or "change shell". We are running it in `sudo` mode for elevated permissions, and we pass it two arguments:

1. `$(which zsh)` - The shell we want to use as the default
2. `$USER` - The user whose default shell we are changing, ie. - you.

After running this command, the next time you start a new terminal session you will see Zsh! To confirm, you can run:

```shell
echo $SHELL
```

## Conclusion

And that's it! Running the commands defined in steps 1 and 2 will turn Zsh into your new default shell. If you have any further questions, or maybe you have a better way of doing this, let me know on [Twitter](https://twitter.com/jakewies)!