How to Change Your Default Shell on Linux with chsh

A stylized shell prompt on a Linux Ubuntu-style laptop system.Fatmawati Achmad Zaenuri / Shutterstock

Bash is not the only Linux shell. It’s easy to try other shells, like Zsh, which is very popular. When you find one, use the chsh command to make it your default shell. We will show you how.

Why a shell is important

The shell is between you and the operating system. It provides the environment inside a terminal window that allows you to type commands and run programs. The shell checks your entry and determines what you want. If he can run your auction himself, he does. If he needs outside help, he searches for the path and finds the programs that can do everything you asked for.

There are many different shells available on Linux. They all allow you to perform the same main tasks: exploring the file system, working with files, launching programs, and running scripts. However, they each perform these tasks in their own way and have their own peculiarities and peculiarities.

Hulls tend to be designed by people who want things to behave in a specific way. If your thinking aligns with that of this designer, this case may well suit you. In addition, trying a new shell on Linux is easy.

In most Linux distributions, including Ubuntu, the default shell is bash. He does a great job and is very capable. However, another shell could offer a time saving difference that would have a significant impact on your workflow. You will never know if you don’t watch!

RELATED: What is ZSH and why should you use it instead of Bash?

A bucket of shells

We have covered the different Linux shells before, but here is a quick introduction to the most common:

hit: the Bourne again the shell is the failure in many distributions.
rbash: This Limit bash shell provides minimal functionality to the person or script running it.
ash: the Almquist shell is a lighter version of bash.
hyphen: The Debian Alquist shell is the default shell script in Ubuntu. While bash is the default login and interactive shell, dash is used to run system processes because it is much lighter than bash.
zsh: The Z shell is a modern version of the bash shell family. It offers neat improvements, such as spelling checks for orders and suggested corrections.
fish: This friendly interactive shell was written from scratch and is not derived from any of the other shell families. It is designed to be user-friendly. Among its many other benefits, fish offers suggested commands based on your history and the contents of the current folder, similar to predictive text.
ksh: The KornShell provides a particularly powerful scripting language.

RELATED: What is the difference between Bash, Zsh and other Linux shells?

List of installed shells

To see what shells are installed on your computer, use this command. It simply lists the contents of the / etc / shells file:

cat / etc / shells

cat / etc / shells in a terminal window.

We mentioned bash, dash and rbash, but what is sh?

sh is the Thompson shell, written in 1971 by Ken thompson of Bell Labs Fame. It is no longer maintained and has long since been replaced by modern shells. It is included only to maintain compatibility with older scripts which still have the following first line:

#! / bin / sh

This tells the system to use the sh shell to execute the script. Do you really have this old shell on your machine, and is it used to run your scripts? The which command will tell us which program is actually running when you type a command.

Let’s see what runs when you type sh:

what sh

It seems to find a binary. if we dig a little deeper, however, we will see that it is a symbolic link which actually points to the dash, the light shell used to execute scripts:

ls -l / bin / sh

which sh in a terminal window.

It is an orderly and lightweight way of providing a safety net for scripts that expect to find sh on modern systems.

Install another shell

Install the fish shell and set it as the default for dave. On Ubuntu, we type the following command:

sudo apt-get install fish

sudo apt-get install fish in a terminal window.

On Manjaro, use pacman:

sudo pacman -Sy fish

sudo pacman -Sy fish in a terminal window.

On Fedora, type the following:

sudo dnf install fish

sudo dnf installs fish in a terminal window.

Once the installation is complete, you can check the installed shells again:

cat / etc / shells

cat / etc / shells in a terminal window.

Our new shell appears as / usr / bin / fish. Note this path: you will need it shortly.

The $ SHELL environment variable

The $ SHELL environment variable contains the name of your current shell. We can check which one is echoed:

echo $ SHELL

Let’s start the fish shell:

fish

Now let’s check again what the $ SHELL environment variable says:

echo $ SHELL

echo $ SHELL in a terminal window.

The first time we use echo $ SHELL, we are in the bash shell. The environment variable contains the path to the bash executable, / bin / bash.

When we launch the fish shell, we receive a friendly welcome message and the command prompt changes. What might be surprising is that the $ SHELL environment always keeps its way to the bash executable, / bin / bash. It’s okay, it’s normal.

When you launch a new shell (or any other program), it inherits the environment of the parent shell. Thus, the fish shell inherits global and exported environment variables from the bash shell. Since the value of the $ SHELL environment variable has not been changed, it has the same value in the fish shell as in the bash shell.

We manage fish like any other program. We can also use exit to exit the fish shell. It closes like any other program, and we return to the bash shell.

It’s great to try new shells, see what they can do, and find out if you get along with them. You can explore before making the jump and adopt one as your reference shell.

If you decide to make fish – or any other shell – your default, you will need to use the chsh command.

The chsh command

The chsh command allows you to change your default shell. The trick is to know that it allows you to change both the default connection and the default interactive shells. You may want to change one or the other, or both.

Each time you log in to get a command prompt, you use the shell configured to be your login shell. When you are already connected and open a terminal window, you use the shell configured to be your interactive shell. They can be identical or different hulls.

To define your login shell, use chsh without parameters:

chsh

chsh in a terminal window.

You are asked to enter your password. Then you need to type the path to the new shell and press Enter.

If we establish a remote connection to this test computer from another, we will end up in the shell of the fish once we have connected.

SSH connection showing the fish shell as a connection shell, in a terminal window.

To change your interactive shell, use chsh with the -s (shell) option. Pass the path to the new shell on the command line:

chsh -s / usr / bin / fish

chsh -s / usr / bin / fish in a terminal window.

You are prompted to enter your password and return to the command prompt of your current shell. You must log out and log in again for the change to take effect. When you do, you’ll see the welcome message and the fish shell command prompt.

The $ SHELL environment variable now contains the path to your new default shell:

echo $ SHELL

echo $ SHELL in a terminal window.

Changing the shell of another user account

If you have root privileges and can use sudo, you can modify the shells of other user accounts. The command is the same as before, with the addition of this person’s username to the command line:

sudo chsh -s / usr / bin / fish mary

sudo chsh -s / usr / bin / fish mary in a terminal window.

The next time Mary connects, she will see the new shell when she opens a terminal window.

user mary at the fish shell command prompt in a terminal window.

Everyone has a favorite

As long as you are comfortable with your choice of shell and it works for you, it’s great! Remember that it must be able to run common scripts, such as installation routines. For the shells mentioned here, this should not be a problem.

Of course, you can also download and install a new shell, and take it for a test drive without making any configuration changes to your computer. When you are ready to tie the knot, chsh will perform the ceremony for you.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.