How to Change the Default Shell in Linux

How to Change the Default Shell in Linux

Most Linux users don't stop to think which shell they interact with. In fact, it's quite possible for you not to be aware of the "shell" at all! You just connect to your server, type in commands and you're done. What is this "shell"?

The shell is basically the program that provides you with the interface to enter your commands and interact with the server. Without it, there would be no place to type your commands, write scripts etc. Linux has a multitude of shells, but the most common is called "bash", which is based on the original "Bourne Shell". It stands for "Born Again SHell". If you don't know which one you're using, chances are that it's bash.

However, the shell can be changed quite easily in Linux. They're just regular programs that you can download from the repositories and execute like any other application. In this tutorial, I'll show you how to find out which shell you're currently using, how to find the default shell, and how to change the default shell for the next time you log in.

How to Know Which Shell You're Currently Using

The value of the shell currently in use is stored in the environment variable $0. So just echo this variable to the screen like this:

echo $0

And it'll tell you which shell you're using. Sometimes, you might need to be sure of its location - for some reason, it might end up being a symbolic link to some other shell! So once you know the name of the shell, you can use the "which" command paired with "ls -l" like this to find out the end location of the file:

ls -l `which bash`

Replace the section in bold with the name you got from the previous echo. You should see something like this:

Over here, you can get the actual location of the bash file in use - "/usr/bin/bash".

How to Know what the "Default" Shell Is

The "echo $0" will show you what's currently being used, but not what's currently loaded as the default bash shell when you log in. To do that, we use another variable called $SHELL. Let's say that I've changed my existing shell from bash, to another one called "tcsh" - a shell whose scripting language is a lot more like C, and was seen as more easily accessible to users already familiar with that language.

Here is the difference between $SHELL and $0:

As you can see, my default shell is still bash, but I'm currently using tcsh, as shown by the $0 variable. No matter how many times you change your shell, the default shell in the $SHELL variable remains the same. So when you log in again, that's the one that's loaded.

Changing the Default Shell on Linux

What if you've found a shell that you really like and want to use it permanently from now on as the default shell for your system? To do that, we need the absolute path of the shell command. First, we get a list of all existing shells on the system by looking at the file "/etc/shells" like this:

As you can see, the csh and tcsh shells were newly added by me. But these are not the absolute paths. To get those, use the "which" command:

which tcsh

Now that we have the absolute path, we use the command:


This will allow us to enter a new default shell command. Use the absolute path - the one you found earlier using the "which" command. This will change the shell, but the $SHELL variable won't change until you relog in. One way of doing that is by using the command:

su [username]

And when you've relogged in the default shell will have changed as shown in the screenshot here:

Change the default shell in Linux

So that's how you find out which shell you're currently using, the default shell, as well as how to change it!

Is Your Website Slow?

A slow website can cost you visitors. Enter your website URL below to test its load speed now and find out how to make it faster:

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclosure: We receive a compensation from some of the companies whose products are presented on our website.