FreeBSD: Install And Use Bash Shell

In Unix like operating systems, a shell is a program that interprets the command, executes, takes input(s), and prints output(s) on the terminal. FreeBSD uses tcsh as the default root shell and sh as the default user shell.

For the purpose of bash scripting, you might need it in FreeBSD. So this article describes how to install and use bash in FreeBSD.

What is bash

Bash is a command-line shell/programming language by the GNU project. Bash or bourne again shell is a sh compatible shell that includes the useful feature of Korn shell(ksh) and C shell(csh). It comes default in various Unix like operating systems such as in GNU/Linux.

How to install bash in FreeBSD

In FreeBSD, there are two ways to install software packages: pkg and ports collection. The pkg is used to install from prebuilt binaries while ports collection is used to install packages from sources. You can use either way to install the bash in your system.

Installing bash using pkg

To install bash using pkg use the following command in your terminal –

# pkg install bash

Installing bash using the ports collection

To install the bash using the ports collection, first, you have to change the directory to the port bash –

# cd /usr/ports/shells/bash

and then use –

# make install clean

Please note that you need to be a root user or have superuser privilege for installing packages in FreeBSD.

Working with the bash shell in FreeBSD

Now bash is installed in your system you can start using it by executing the following command –

# bash


# /usr/local/bin/bash

This will change the current shell into the bash.

How to set bash as default shell

First, find the location where bash is installed by using –

# whereis bash

To set bash as the default shell for the current user, use-

# chsh -s /usr/local/bin/bash

Or if you want to set it the default for another user then use –

# chsh -s /usr/local/bin/bash {Username}

For example –

# chsh -s /usr/local/bin/bash lalit

Now if you want to set tcsh or sh your default shell again then use –

# chsh -s /bin/tcsh

OR use –

# chsh -s /bin/sh


After installing bash, you could now add the bash-completion feature in your system. If you want to say something on this topic then write to us in the comments below.

Leave a Comment

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

Exit mobile version