Need help? Chat now!
Search results for:
Table of Contents
In Linux servers, the shell is the primary component used in operating the server and allows you to connect to your server remotely. When you log in via SSH, it is displayed to you, analyzes the commands passed to it and spawns processes to execute those commands. However, at its core, the shell is just software 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. They can either be installed via your distribution's package manager or following the instructions from the shell's maintainer.
The Bourne Again Shell (Bash) is by far the most common 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 times.
You can also create aliases from one command name to another, so if you need to run a really long command consistently, you can alias to a shorter command, almost like a nickname.
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.
The 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 to check 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 to function properly. This will 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 you do need to install Bash for whatever reason, 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.
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. ~/.bashrc so that the configurations 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 have implemented your changes.
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 search your command history recursively quickly.
But what really makes it stand out, though, is its 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.
To install Zsh itself, you can install it from your package manager:
yum install -y zsh
Then 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:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Note: The Zsh installation script requires having the git package installed.
If you do not already have that installed, you can run:
yum install -y git
You can copy the template configuration provided in the package as a starting point for your own configuration:
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc source ~/.zshrc
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; 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 log in to the shell, the changes will be automatically applied.
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 it 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 is that it stores the exit status of the last command in a variable called $status.
To install Fish, you can install it via your package manager:
yum install -y fish
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:
wget https://download.opensuse.org/repositories/shells:fish:release:3/RHEL_7/shells:fish:release:3.repo -P /etc/yum.repos.d
You can also find links to the specific instructions for your Linux distributions on the front page of their website.
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 its web-based editor, which you can launch simply by running the following command:
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, 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.
In most Linux distributions, the currently being used shell is stored in an environment variable called $SHELL.
You can check the value of that variable by using the echo command on it:
echo $SHELL /bin/bash
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:
chsh -s /path/to/shell user
For that, you would replace the 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 its location by using the which command like in this example:
which bash /bin/bash
After changing the shell, run exit to close your session and reconnect/login to the server. It should load to the new shell that you set.
Written by Hostwinds Team / June 27, 2019