≡ Menu

FreeBSD Install BASH Shell

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. However, you can easily install and use bash as shell.

Install bash under a FreeBSD unix

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

To install FreeBSD binary package, enter (older version/method):
# pkg_add -r bash
Or to install the port:
# 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 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:

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, enter:
grep vivek /etc/passwd

egrep --color 'vivek|zsh' /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.
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 9 comments… add one }
  • duzap May 22, 2009, 8:12 am

    This was very usefull for me, thank you.

  • matt November 22, 2009, 6:43 pm


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

  • Nazar August 4, 2010, 1:00 am

    Thanks a lot! Very clearly written and useful!

  • DJNeo August 5, 2010, 2:14 am

    Very usefull,10x alot!!!

  • George December 14, 2010, 12:09 pm

    Thanks a lot! Exactly what I needed!

  • Chuck Moyes March 22, 2011, 8:50 pm

    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 March 28, 2011, 10:46 pm

    Thank you!!!:)

  • Alex June 10, 2012, 10:27 am

    Thanks a lot! Just used it. =)

  • Uwe September 24, 2012, 8:25 pm

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

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , ,