Search The Hostwinds Guides Knowledge Base

Alternative Linux Shells

Share This Article

In Linux servers, the shell is the primary component used in operating the server and allows you to remotely connect to your server. It is what is displayed to you when you log in via SSH, analyzes the commands passed to it and spawns processes to execute those commands. However, at its core, the shell is just software that is installed on the server and acts as an interface to the underlying kernel and the rest of the operating system.

Because the shell is just a piece of installed software, you can install and use multiple shells, and change what shell you want to use by default when you log in.

While there are thousands upon thousands of custom shells available to use, and you could even make your own, this guide will be going over the features and installation instructions for three of the most popular Linux shells: bash, zsh, and fish.

The installation instructions provided in this guide are for CentOS 7. All of the shells mentioned in this guide are available for other distributions as well, and can either be installed via your distribution’s package manager, or following the instructions from the shell’s maintainer.


Bash

The Bourne Again Shell (Bash) is by far the most common shell in use today. It has become the standard for what a shell should be, and as such is the default shell shipped with the vast majority of Linux distributions.

Some of the most useful features of the Bash shell are that it allows the use of loops and conditional statements, allowing repetition and boolean expressions to control what gets executed, and how many time.

You can also create aliases from one command name to another, so if you need to consistently run a command that is really long, you can alias it to a shorter command, almost like a nick-name.

It also supports variable assignments, functions, as well as bracket and tilde expansions.

All of these combined can extend the usage of the shell from just a way to launch other programs, into being able to be used as a custom program itself. This is often done via the use of shell scripts.


Installation

Odds are that you are already using Bash, as it is the default shell shipped with most Linux distributions. You can verify that it is already your shell by following the instructions below for checking what shell you’re currently using.

If that is the case, then there is nothing to do to install it.

If you do change to a different shell, you will not want to, and likely will not be able to, uninstall Bash from your system. This is because the default shell acts as a dependency on many base packages of the system for them to function properly. This will just mean that Bash is still installed and available for any packages to reference, and you can use or change back to it at any time.

If for whatever reason you do need to install Bash, you may be able to install it via your package manage just by installing the bash package. Otherwise, you can also download the latest version of the source code from here, then compile and install it manually.


Configuration

All the configuration for Bash can be put into a file called .bashrc, located in your home folder. It is in there that you can configure things like functions or command aliases.

Once any changes are made and saved to the .bashrc file, you can apply the changes to your current session by running the command source ~/.bashrc or . ~/.bashrc so that the configuratons are reloaded in your current session. This will also ensure that these changes are loaded the next time you log in to the shell and has implemented your changes.


Zsh

Zsh is another fairly popular shell, which by itself, isn’t too different from Bash. It has a few notable additional functions, such as auto-suggesting commands based on your command history, and being able to quickly search your command history recursively.

But what really makes it stand out though, is it’s integration with a framework called oh-my-zsh.

Oh-my-zsh is an open-source, community driven framework with thousands of predefined plugins for your Zsh configuration. These plugins range anywhere between providing you preset helper variables and functions, shell themes and syntax highlighting, extensibility for common utilities, to even having the shell give you a Chuck Norris joke upon login.

Once installed, oh-my-zsh integrates with Zsh via your Zsh configuration file, located at ~/.zshrc. Whenever changes are made to that configuration file, the next time you load the shell (i.e. from logging in), your changes will be applied.


Installation

To install Zsh itself, you can simply install it from your package manager:

Then simply run the zsh command to enter the Zsh shell.

To install oh-my-zsh, run the following command to download and run their installation script:

Note: The Zsh installation script requires having the git package installed.

If you do not already have that installed, you can run:


Configuration

You can copy the template configuration provided in the package as a starting point for your own configuration:

You can then edit that configuration file to customize your Zsh. The ZSH_THEME statement sets what theme the shell should use from the available themes. And the plugins=( ) statement specifies what available plugins are to be installed and enabled; simply add the name of the plugin between the parentheses, separated by spaces.

You can then run the command source ~/.zshrc to apply the changes to your current session, and the next time you login to the shell, the changes will be automatically applied.


Fish

Fish as a shell aims to be a powerful and customizable, yet user friendly shell out of the box.

Some of the best features of Fish are that it provides a web-based configuration editor, to easily and visually edit the look and feel of the shell.

It offers smart autosuggestions that adjust as you type. What differentiates this from other autosuggestions (like Zsh’s) is that not only does it provide suggestions based on your history, but also analyzes the man page of the command you’ve typed in to suggest possible arguments and flags for that command.

It also performs syntax highlighting as you type, where if no command or file is found for what is currently written, it displays as red, otherwise if it is found, it will display as blue

Another small nicety of it is that it stores the exit status of the last command in a variable called $status.


Installation

To install Fish, you can simply install it via your package manager:

Note: you may also ensure that you are using the most up-to-date version by adding the official repo to your system before running the above command:


You can also find links to the specific instructions for your Linux distributions on the front page of their website.


Fish Configuration

The configuration for Fish is stored in a file called .fishrc, located in your home folder. And while you can edit that file directly, one of Fish’s big features is it’s web-based editor which you can launch simply by running the following command:

Fish's web-based configuration editor
Fish’s web-based configuration editor

That command will then launch your web-browser and bring up a page that allows you to customize the theme of the shell, the display and features of the prompt (for example, the Vcs prompts display details about the git repository and branch you are currently navigating), as well as lets you customize the built in shell functions, variables, key bindings and abbreviations.

This page also gives you a visual way to check your command history.

Once done editing, simply close your browser and press ENTER in the shell window you ran fish_config from. Then the changes should be applied immediately, and will be retained the next time you log in.


How to Check What Shell You Are Using

In most Linux distributions, the shell that is currently being used is stored in an environment variable called $SHELL.

You can check the value of that variable by using the echo command on it:


Change Default Shell

To change the default shell for your account (or another account if you have sudo/root privileges), you can use the chsh command in the following format:

For that, you would replace user with the username of the account you want to change the shell for (i.e. root), and replace /path/to/shell to the file path for the shell you want to use. If you don’t know the location of your shell, after you’ve installed a shell, you can find it’s location by using the which command like in this example:

After changing the shell, simply run exit to close your session, and reconnect/login to the server. It should load to the new shell that you set.


Related Articles