FreeBSD Install BASH Shell Using pkg command

last updated in Categories , , , ,

I would like to Bash shell under FreeBSD for bash programming. How do I install bash shell under FreeBSD UNIX operating system?

Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. csh / tcsh (C shell with file name completion and command line editing) is the default shell under FreeBSD. Bash is a much better shell as compared to csh or tcsh. Hence, I recommend installing it. You can easily install and use bash as shell on FreeBSD based VPS or cloud server. This page shows how to install bash shell on FreeBSD operating system.


Update your FreeBSD system

Run the following pkg command to update all install packages:
# pkg update
# pkg upgrade

Sample session:

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking for upgrades (3 candidates): 100%
Processing candidates (3 candidates): 100%
The following 2 package(s) will be affected (of 0 checked):
Installed packages to be UPGRADED:
	ca_root_nss: 3.40.1 -> 3.45
	amazon-ssm-agent: 2.0.790.0_1 -> 2.3.612.0
Number of packages to be upgraded: 2
The process will require 66 MiB more space.
18 MiB to be downloaded.
Proceed with this action? [y/N]: y

FreeBSD install Bash SHELL

Login as root and type any one of the following commands to install bash. On a newer version of FreeBSD use the following command (recommended method):
# pkg install bash
Sample outputs:

Fig.01: Howto Install BASH in FreeBSD using pkg Command
Fig.01: Howto Install BASH in FreeBSD using pkg Command

Install Bash shell using pkg_add

To install FreeBSD binary package, enter (older version/method):
# pkg_add -r bash

How to Install Bash Shell on FreeBSD using ports

To install the bash shell port, run:
# portsnap update extract
# cd /usr/ports/shells/bash
# make install clean

How do I use bash shell under my FreeBSD based system?

To use bash shell, enter:
# bash
# /usr/local/bin/bash


The GNU bash under FreeBSD 11.x and older requires fdescfs (file-descriptor file system) mounted on /dev/fd. To mount it auotmatically type the following command to update /etc/fstab file on FreeBSD:

## append the following to /etc/fstab file under FreeBSD 11.x and older ##
echo "fdesc  /dev/fd  fdescfs  rw 0 0" >> /etc/fstab

How do I set bash as a default shell?

To set bash as default, shell enter:
# chsh -s /usr/local/bin/bash {username}
# chsh -s /usr/local/bin/bash vivek
# chsh -s bash

Verify that bash is default shell for a user account called vivek using grep command/egrep command, enter:
grep vivek /etc/passwd
egrep --color 'vivek|bas' /etc/passwd
finger vivek
Sample outputs:

Login: vivek          			Name: Vivek Gite
Directory: /home/vivek              	Shell: /usr/local/bin/bash
On since Tue May  8 02:15 (IST) on pts/0 from
No Mail.
No Plan.

How to install bash completion on FreeBSD

Type the following pkg command:
# pkg install bash-completion

How to Install bash auto completion on FreeBSD
How to Install bash auto completion on FreeBSD

To enable the bash completion library, add the following to your ~/.bashrc or ~/.bash_profile file:

[[ $PS1 && -f /usr/local/share/bash-completion/ ]] && \
	. /usr/local/share/bash-completion/

Log out and log in again to test new settings.


And there you have it, bash shell installed and working on FreeBSD. However, for root user use the default /bin/csh for security reasons. Do not change /bin/csh to /usr/bin/local/bash for root user. See my bash shell scripting tutorial for more info or GNU/bash homepage here.


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at

Historical Comment Archive

9 comment

  1. I think the portsnap part (updating the system port tree) needs clarification.

    From the FreeBSD Handbook:

    First run:
    # portsnap fetch
    to download a new port tree from the Internet.

    If you haven’t run portsnap before (first time updating after new installation):
    # portsnap extract

    Then always run:
    # portsnap update

    FreeBSD complained about running update before extract when I tried doing what the guide on this web page said to do. Let me know if I’m misinterpreting something.

    Still, have a question? Get help on our forum!