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 and I learned how to set Zsh as my default shell the right way. Here's how:
How you install Zsh is up to you. Checkout this GitHub gist 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.
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
You will see a list of filepaths that each point to an executable file.
# 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
One of these executables is your current shell. You can see your current shell by running:
The output of the command above will be an executable file that resides within
/etc/shells list. For example, if I run the
echo command above, the
output I see is:
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:
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.
For example, running the command above may yield:
If you see no output at all, then you probably don't have Zsh installed. See Prerequisites.
Once we have the location of Zsh's exectuable file, we can "pipe" it to another command:
sudo tee -a /etc/shells
tee utility, which we are running in
sudo, takes an input and appends it
Together, the full command is:
command -v zsh | sudo tee -a /etc/shells
| 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:
- Locate the filepath of Zsh
- Append the filepath to
After running the full command you should see Zsh's executable at the bottom of
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:
sudo chsh -s $(which zsh) $USER
The command above is
chsh -s, or "change shell". We are running it in
mode for elevated permissions, and we pass it two arguments:
$(which zsh)- The shell we want to use as the default
$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:
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!