First see if you even need to switch, or if you’re already using the shell you want by printing the name of the current shell.
$ echo $0 bash
You may have come across the
$SHELL environment variable, but it won’t always do what you expect it to do as you can see below when I switch to
bash is still the value of
$SHELL, so you’re better off just relying on
$ echo $SHELL bash $ zsh $ echo $SHELL bash
So if I’ve confirmed I’m using
bash and I actually want to tinker with
zsh, I can either invoke
zsh as above to use it temporarily, or I can make it my default shell, so it will be the shell used automatically in new terminal sessions.
Changing your default (or login) shell is done using the
chsh utility. First we’ll list the available shells to make sure it’s been correctly installed.
$ chsh -l /bin/sh /bin/bash /bin/zsh /usr/bin/zsh
Which is simply the contents of
$ cat /etc/shells /bin/sh /bin/bash /bin/zsh /usr/bin/zsh
Now I invoke
chsh and specify the shell I want to use.
$ chsh -s /usr/bin/zsh Changing shell for trevor. Password: Shell changed.
And after logging out and logging back in (just opening a new terminal won’t work) I can confirm that
zsh is now my shell.
$ echo $0 zsh