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
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:

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
OR
# /usr/local/bin/bash
Configuration
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:
## append the following to /etc/fstab file ## echo "fdesc /dev/fd fdescfs rw 0 0" >> /etc/fstab |
## append the following to /etc/fstab file ##
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
OR
egrep --color 'vivek|bas' /etc/passwd
OR
finger vivek
Sample outputs:
Login: vivek Name: SXI ADMIN Directory: /home/vivek Shell: /usr/local/bin/bash On since Tue May 8 02:15 (IST) on pts/0 from 192.168.1.5 No Mail. No Plan. |
Login: vivek Name: SXI ADMIN
Directory: /home/vivek Shell: /usr/local/bin/bash
On since Tue May 8 02:15 (IST) on pts/0 from 192.168.1.5
No Mail.
No Plan.
How to install bash completion on FreeBSD
Type the following pkg command:
# pkg install bash-completion

To enable the bash completion library, add the following to your ~/.bashrc or ~/.bash_profile file:
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] &&
. /usr/local/share/bash-completion/bash_completion.sh
|
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] &&
. /usr/local/share/bash-completion/bash_completion.sh
Log out and log in again to test new settings.
Conclusion
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.
(adsbygoogle = window.adsbygoogle || []).push({});