FreeBSD Install BASH Shell Using pkg command

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.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements FreeBSD Unix
Est. reading time 3 minutes

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 pkg command (recommended method):
# pkg install bash

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

Installing 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:
# **[ first time user must run fetch and extract command once ] ** #
# portsnap fetch # <-- first time command only
# portsnap extract # <-- first time command only
# 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
We can print or check my bash version as follows:
bash --version
I am using 5.0.18 on FreeBSD 12.2p1:

GNU bash, version 5.0.18(3)-release (amd64-portbld-freebsd12.1)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Want to print or display your FreeBSD version along with GNU/BASh version? Try:
$ freebsd-version
$ uname -mrs


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

You will get confirmation on the screen:

chsh: user information updated

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

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • duzap May 22, 2009 @ 8:12

    This was very usefull for me, thank you.

  • matt Nov 22, 2009 @ 18:43


    Just trying out freebsd, and the first thing I noticed was there was no bash!

  • Nazar Aug 4, 2010 @ 1:00

    Thanks a lot! Very clearly written and useful!

  • DJNeo Aug 5, 2010 @ 2:14

    Very usefull,10x alot!!!

  • George Dec 14, 2010 @ 12:09

    Thanks a lot! Exactly what I needed!

  • Chuck Moyes Mar 22, 2011 @ 20:50

    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.

  • Rui Mar 28, 2011 @ 22:46

    Thank you!!!:)

  • Alex Jun 10, 2012 @ 10:27

    Thanks a lot! Just used it. =)

  • Uwe Sep 24, 2012 @ 20:25

    Thank you for this post. It was very useful for me!

  • Lavina Dec 30, 2020 @ 20:19

    Fantastic. I do not like this tcsh/csh and I prefer bash just like macOS on my mac book air.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum