Believe it or not the Bash shell does not come installed on the system. By default FreeBSD uses the sh shell (after the rewrite under the BSD license on 1989 of the original Bourne Shell found on UNIX, which had inherited the ‘sh’ name from the original’s Thomson shell), the C shell or the tcsh shell. As on any other UNIX system you can change the shell and install others that do not come on the base system, say the dash shell or the zsh one. For a regular user changing the default shell does mean almost nothing, specially if this is going to be used as a regular PC. However if you are going to use this system as a development machine or the like you may want to use a different shell. The Bash shell is a very popular one among programmers nowadays and system administrators as well. Hence this short simple article on how to install the bash shell on FreeBSD.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.
So you said you wanted bash. Let’s install it. Before anything update your pkg source by:
sudo pkg upgrade
Let’s now install bash:
albert@Apache:~ % sudo pkg install bash
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
bash: 4.4.23_1
Number of packages to be installed: 1
The process will require 8 MiB more space.
1 MiB to be downloaded.
Proceed with this action? [y/N]: y
[Apache] [1/1] Fetching bash-4.4.23_1.txz: 100% 1 MiB 488.8kB/s 00:03
Checking integrity... done (0 conflicting)
[Apache] [1/1] Installing bash-4.4.23_1...
[Apache] [1/1] Extracting bash-4.4.23_1: 100%
albert@Apache:~ %
You may also want tab auto-completion so you want to install the bash-completion package.
albert@Apache:~ % sudo pkg install bash-completion
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
bash-completion: 2.8_1,1
Number of packages to be installed: 1
199 KiB to be downloaded.
Proceed with this action? [y/N]: y
[Apache] [1/1] Fetching bash-completion-2.8_1,1.txz: 100% 199 KiB 68.0kB/s 00:03
Checking integrity... done (0 conflicting)
[Apache] [1/1] Installing bash-completion-2.8_1,1...
[Apache] [1/1] Extracting bash-completion-2.8_1,1: 100%
Message from bash-completion-2.8_1,1:
=====================================================================
To enable the bash completion library, add the following to
your .bashrc file:
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] && \
source /usr/local/share/bash-completion/bash_completion.sh
See /usr/local/share/doc/bash-completion/README.md for more information.
=====================================================================
albert@Apache:~ %
You can already change your default shell to use bash if that is what you desire. Use the handbook chapter to do so.
https://www.freebsd.org/doc/handbook/shells.html
However you may want to configure bash just a bit. If so read on this how to install the bash shell on FreeBSD guide.
You have to create a configuration file named .bashrc, .bash_profile inside your home directory.
albert@Apache:~ % touch .bashrc
albert@Apache:~ %
This file is empty. Let’s fill it up.
For the auto-completion to work you may add what you were told at install time:
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] && \
source /usr/local/share/bash-completion/bash_completion.sh
Now you may want to add a few aliases. An alias works to avoid typing a command an a series of flags. For example the ‘ll’ command is the short form of ‘ls -la’. These are the aliases I’ve added to mine:
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -lhA'
You may want to add some color to the ouput of the shell. There is a environment variable you can enable by adding the following to your bash config file:
export CLICOLOR="YES"
export LSCOLORS="ExGxFxdxCxDxDxhbadExEx"
To make use of bash with this configuration you can just type ‘bash’ at your command prompt and you will see the change.
albert@Workstation:~ %
albert@Workstation:~ % bash
[albert@Workstation ~]$
Notice the brackets and the dollar sign instead of the percentage at the end of the line.
If you want the bash shell to be your default shell you can do it by following what the manual states. In short here you have it:
Find the path of the bash binary.
[albert@Workstation ~]$ which bash
/usr/local/bin/bash
[albert@Workstation ~]$
With the path use the change shell command.
albert@Apache:~ % chsh -s /usr/local/bin/bash albert
Password:
chsh: user information updated
albert@Apache:~ %
Log out of all your sessions and get back in. By default your shell should’ve changed. In order to check it you can do:
albert@Apache:~ % finger albert
Login: albert Name: Albert Valbuena
Directory: /home/albert Shell: /usr/local/bin/bash
Last login Sun Nov 4 21:05 (CET) on pts/3 from 192.168.1.35
No Mail.
No Plan.
albert@Apache:~ %
When logged back in:
[albert@Apache ~]$ finger albert
Login: albert Name: Albert Valbuena
Directory: /home/albert Shell: /usr/local/bin/bash
Last login Sun Nov 4 21:05 (CET) on pts/3 from 192.168.1.35
No Mail.
No Plan.
[albert@Apache ~]$
As a last note take in consideration that bash doesn’t need the fdescfs (file-descriptor file system) mounted at runtime. But some GNU/Linux scripts may need it so. To momentarily enable the functionality type the following:
mount -t fdescfs null /dev/fd
In order to make this last thing permanent edit the /etc/fstab file and add the following line:
fdesc /dev/fd fdescfs rw 0 0
You can go crazy configuring bash. There are many other guides on the internet for you to follow. Use whatever fits your needs and enjoy your time with it. This is all for my how to install the bash shell on FreeBSD guide.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.