Bored With Bash? Change the Default Shell in Linux

Bash is not the only shell out there. There are many other shells available with slightly different feature sets. A few examples are Zsh, Fish, Ksh are Xonsh.

You can have more than one shell installed on your system at any given time.

If you want to choose some other shell as your default, you can use the chsh command in this fashion:

chsh -s path_to_binary_of_shell

You can get the path of the binary of the shell by displaying the contents of the /etc/shells file. You may also use the command below that automatically gets the binary of the desired shell with the which command:

chsh -s $(which new_shell)

Let’s see things about knowing and changing shells a bit more in detail here.

How to know which shell are you using currently?

There are a few ways to figure out which shell is being used currently, although the accuracy of these methods can be debatable by the experts.

The simplest and most common way is to use:

echo $0

$0 is a special shell variable that gets you the name of the shell or shell script (if you are using it in a script).

Checking current shell in use in Linux

Another method is to use check the process using:

ps -p $$

Here, $$ gives you the process ID of the current process/shell.

Check current shell using process ID

How to install another shell?

Well, like any other software package. Most of the popular shells, like Fish and Zsh, are available from your distribution’s repository and can be installed easily. The newer, lesser-known shells, like Xonsh, may have a different installation instruction. You can get that from the project’s web page.

Let’s say you want to install Zsh on Ubuntu. Use:

sudo apt install zsh

How to change the current shell?

Now that you have installed another shell, let’s see about changing it.

Most likely, you just have to enter the name of the shell. Say, you have to switch to Zsh:

zsh

To exit from the current shell, enter exit and you’ll be back to the default shell.

How to know the default shell?

There is this SHELL environment variable that tells you the default shell for the current user:

echo $SHELL

Let’s take this example where I switched to Zsh. The current shell shows to zsh and the default shell remains bash:

Current shell vs default shell

This tells you that changing the shell won’t change the default shell. Which means the next time you log into the terminal/system, you’ll be back to the old default shell instead of the newly one.

How to know the available shells on your system?

You can see the available shells in your system by looking at the content of the /etc/shells:

cat /etc/shells

Here are the presently available shells in my system:

Available shells in Linux

How to change the default shell?

The contents of the /etc/shells file shows the location of binaries of the available shell. You have to use it with the chsh command.

Let’s say, I want to make the Zsh shell the default. Here’s what I use:

chsh -s /usr/bin/zsh

Log out and log in again to see the changes.

Note that this will change the default shell of the current user. If you are an admin and want to change the default shell for another user, use:

sudo chsh -s /usr/bin/zsh other_username

Conclusion

Linux is all about choices. You have the liberty to make changes as you wish. This is another example where you are not bound by the choice of the default shell your distribution provides. You can change the shell to the one you prefer. Enjoy 😄