Home Ubuntu How to install and use Fish Shell on Ubuntu

How to install and use Fish Shell on Ubuntu

Enter Fish Shell, an interactive and smart command line shell that offers advanced features like autosuggestions, syntax highlighting, and tab completions.

by Tony Gidraph
installing and using fish shell on ubuntu

Fish shell, also known as Friendly Interactive Shell, is a user-friendly shell designed for interactive use in Unix-like operating systems. Fish shell provides many features and customization options, such as syntax highlighting, autosuggestions, and tab completions.

In this article, we will guide you through the process of installing and using Fish shell on Ubuntu.

Installing Fish Shell on Ubuntu

There are multiple ways to install Fish shell on Ubuntu. Here are some of the most commonly used methods:

Method 1. Install Fish Shell using the apt package manager (Recommended)

The apt package manager is the most straightforward way to install Fish shell on Ubuntu. Run the following command in your terminal:

sudo apt update
sudo apt install fish

This will install the latest version of Fish shell from the Ubuntu repositories.

install fish shell

Install Fish Shell

Method 2. Install Fish Shell Using PPA

If the version of Fish shell available in the Ubuntu repositories is not up-to-date, you can add the Fish shell PPA (Personal Package Archive) to your system and install the latest version. To do this, run the following commands:

sudo apt-add-repository ppa:fish-shell/release-3
sudo apt update
sudo apt install fish

This will install the latest version of Fish shell from the PPA.

Method 3. Install Fish Shell by building from Source

If you prefer to build and install Fish shell from source, you can download the source code from the Fish shell website and compile it on your system. Here are the steps to do that:

sudo apt install build-essential cmake
wget https://github.com/fish-shell/fish-shell/releases/download/3.3.1/fish-3.3.1.tar.gz
tar -xzf fish-3.3.1.tar.gz
cd fish-3.3.1
cmake .
make
sudo make install

This will compile and install the latest version of Fish shell on your system.

Using Fish Shell

Once Fish shell is installed on your Ubuntu system, you can start using it by opening a terminal and typing the command below in the command prompt.

fish

This will launch the Fish shell, and you can start using its features and customization options.

start fish shell

Start Fish Shell

Fish Shell features

After executing the “fish” command, there are a few changes that you will notice on the terminal when you try executing commands. These include:

1. The prompt

When you start the Fish shell, you will notice that the prompt looks different from the default Bash prompt. The Fish prompt is usually a simple “>” symbol followed by a space. However, you can customize the prompt to display different information, such as the current directory, username, hostname, or Git branch, by using the “set” command with the “fish_prompt” variable.

For example, if you want to display the current directory in the prompt, you can run the following command:

set fish_prompt "%c> "

This will display the prompt’s current directory followed by a “>” symbol.

show current directory in the prompt

Show the current directory in the prompt

If you want to display the current time on the prompt, you can use the “date” command with the “fish_prompt” variable to display the current time in the desired format.

Here’s an example command that you can use to display the current time in the “HH:MM:SS” format:

function fish_prompt
set_color $fish_color_cwd
echo -n (date +%H:%M:%S)' '
printf '%s ' (prompt_pwd)
set_color normal
echo -n '> '
end

This command defines a Fish shell function called “fish_prompt” that sets the prompt to display the current time followed by the current directory and a “>” symbol. The “set_color” commands set the color of the directory information to match the Fish shell theme.

change fish shell prompt

Change Fish Shell prompt

2. Welcome message:

When you start the Fish shell for the first time, you will see a welcome message giving you some information about it and its features. The welcome message includes some helpful tips and commands that you can use to get started with Fish shell.

fish welcome message

Fish welcome message

You can modify or disable the Fish welcome message by modifying the “fish_greeting” variable.

You can modify the greeting by setting the “fish_greeting” variable to the desired message. For example, to set the greeting to “Welcome to Fish shell!”, you can run the following command:

set fish_greeting "Welcome to Fish shell!"

This will set the “fish_greeting” variable to the specified message, displayed every time you start a new Fish shell session.

fish shell welcome message

Fish shell welcome message

To disable the greeting altogether, you can set the “fish_greeting” variable to an empty string:

set fish_greeting ""

This will remove the greeting message from the Fish shell startup.

disable fish shell welcome message

Disable Fish Shell welcome message

3. Syntax highlighting:

Fish shell provides syntax highlighting for commands and their arguments. This means that commands and their arguments are highlighted in different colors to make them easier to read and understand.

For example, if you type a command such as “ls -l,” the “ls” command will be highlighted in one color, and the “-l” option will be highlighted in another color.

syntax highlighting

Syntax highlighting

You can enable syntax highlighting in Fish shell by running the following command:

set fish_syntax_highlighting

5. Autosuggestions

Fish shell provides an autosuggestions feature, which suggests commands and arguments based on your previous commands and the contents of your command history. For example, if you type “git co” and press the tab key, Fish shell will suggest the “checkout” command based on your previous use of Git.

autosuggestions

Autosuggestions

You can enable autosuggestions in the Fish shell by running the following command:

set fish_autosuggestions

6. Tab completions

Fish shell provides tab completions, which means it completes commands and arguments as you type them. For example, if you type “ls /u” and press the tab key, Fish shell will complete the path “/usr” based on the contents of your file system.

You can enable tab completions in Fish shell by running the following command:

set fish_complete_path

These are just a few of the many features and customization options that Fish shell provides. By using these features, you can make your terminal experience more user-friendly and efficient.

Setting Fish as your default shell

Use the command below to set Fish as your default shell.

chsh -s /usr/bin/fish

This command uses the “chsh” (change shell) utility to set the default shell for your user account to Fish shell. The “-s” option specifies the path to the Fish shell executable /usr/bin/fish on Ubuntu.

You will be prompted to enter your password to confirm the change. Enter your password and press Enter.

set fish shell as the default shell

Set Fish Shell as the default shell

Once the change is confirmed, log out of your current session and log back in to start a new session with Fish shell as your default shell. To verify that Fish shell is now your default shell, run the following command:

echo $SHELL

This command should output the path to the Fish shell executable, which confirms that Fish shell is now your default shell.

verify shell

Verify shell

Switching to Bash Shell

If you no longer want to use Fish shell as your default shell and switch back to Bash, you can do so by running the command below.

chsh -s /bin/bash

This command uses the “chsh” (change shell) utility to set the default shell for your user account to Bash shell. The “-s” option specifies the path to the Bash shell executable, “/bin/bash” on Ubuntu.

You will be prompted to enter your password to confirm the change. Enter your password and press Enter.

switch to bash

Switch to bash

Once the change is confirmed, log out of your current session and log back in to start a new session with Bash shell as your default shell.

Conclusion

Fish shell is a user-friendly shell designed for interactive use in Unix-like operating systems. With its syntax highlighting, autosuggestions, and tab completions features, Fish shell provides many customization options. The installation process of Fish shell on Ubuntu is simple and can be done through multiple methods.

Once installed, users can use its features and customization options, such as customizing the prompt, modifying the welcome message, enabling syntax highlighting, and autosuggestions to enhance their terminal experience.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.