OpenBSD Install BASH Shell Package Command

How do I install BASH shell package under OpenBSD operating system? How do I set bash as a default login shell under OpenBSD?

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsOpenBSD
TimeN/A
You need to use the pkg_add commandto install BASH package which is available in a binary packages format over the Internet. You can also install bash package using OpenBSD CD during installation. This page shows how to install bash shell on OpenBSD.

ADVERTISEMENTS

OpenBSD Install BASH Shell Command

First, Login as a root user, either use su - or sudo or doas command as per your environment:
$ su -

Search for OpenBSD installation path

One can set up PKG_PATH using export command. You can make things really easy by using the PKG_PATH environment variable. Just point it to your favorite location, and pkg_add will automatically look there for any package you specify, and also fetch and install the necessary dependencies of this package automatically (see mirror list here).
$ export PKG_PATH=ftp://mirror.planetunix.net/pub/OpenBSD/`uname -r`/packages/`machine -a`/
Or add to your ~/.profile (sh/ksh/bash) file as follows:

echo 'export PKG_PATH=https://cdn.openbsd.org/pub/OpenBSD/`uname -r`/packages/`machine -a`/' >> ~/.profile

Caution: The PKG_PATH variable MUST end in a slash (/).

Please note that the /etc/installurl file contains a single line specifying an OpenBSD mirror server URL. You can view it with the help of cat command:
$ cat /etc/installurl
Update the file as follows if it is empty, run the echo command:
echo 'https://cdn.openbsd.org/pub/OpenBSD/' > /etc/installurl
Now search for bash package, run:
# pkg_info search bash
OpenBSD Install BASH Shell

OpenBSD Install bash shell binary package

Use pkg_add command as follows (older version):
# pkg_add -i -v bash
On newer system skip the -i option:
# pkg_add -v bash
One can use doas as follows (if configured on your system):
$ doas -u root pkg_add -v bash
Sample outputs from OpenBSD 4.x:

parsing bash-3.2
Dependencies for bash-3.2 resolve to: gettext-0.14.6, libiconv-1.9.2p3 (todo: libiconv-1.9.2p3,gettext-0.14.6)
bash-3.2:parsing libiconv-1.9.2p3
bash-3.2:libiconv-1.9.2p3: complete                                                                                                                                           
bash-3.2:parsing gettext-0.14.6
Dependencies for gettext-0.14.6 resolve to: expat-2.0.0, libiconv-1.9.2p3 (todo: expat-2.0.0)
bash-3.2:parsing expat-2.0.0
bash-3.2:expat-2.0.0: complete                                                                                                                                                
bash-3.2:gettext-0.14.6: complete                                                                                                                                             
Shell /usr/local/bin/bash appended to /etc/shells
bash-3.2: complete

Sample outputs from OpenBSD 5.9 (please note that you no longer need to pass the -i option to OpenBSD):

Fig.01: Installing bash shell on OpenBSD 5.9

Fig.01: Installing bash shell on OpenBSD 5.9

To use bash shell, just enter bash command:

$ bash

How do I setup bash as a login and default shell for my account?

Type the following chsh command to change the user’s shell to new shell called /usr/local/bin/bash (the following will change root shell to bash):
# chsh -s /usr/local/bin/bash
Set bash shell as a default login shell for user nixcraft:
# chsh -s /usr/local/bin/bash nixcraft

Conclusion

You just learned about setting up gnu/bash shell using the pkg_add on OpenBSD system.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • Dirkgent2ly Feb 18, 2009 @ 9:10

    Nice guide. Uh, how do you do this permanently?

  • Dirkgent2ly Feb 20, 2009 @ 0:23

    ok, chsh did it for me:

    chsh -s bash

    Got:

    chsh: warning, unknown root shell

    I had to logout and login again for it to take effect.

    To make known a bashrc, I added to ~/.profile

    source ~/.bashrc

    Good tutorials Vivec, always enjoy reading your posts.

  • The Doctor Jun 13, 2009 @ 0:10

    Perfect installation, but any follow-up for setting bash color profiles? I’ve noticed 4.5 *doesn’t* like using .bashrc (GNU/Linux) opting for .bash_profile, nor do the numerous online Linux how-tos/guides (ie: http://wiki.archlinux.org/index.php/Color_Bash_Prompt) adapt themselves to OpenBSD.

    OpenBSD 4.5 w/ bash 3.2.48

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.