Blog

03/06/2019

How to install bash shell in Alpine Linux



How do I install bash shell in my Alpine Linux LXD (Linux Container) virtual machine (VM)?

Alpine Linux comes with BusyBox. It is described as, “The Swiss Army Knife of Embedded Linux.” BusyBox combines tiny versions of many common UNIX utilities into a single small executable including /bin/sh. By default, bash is not included with BusyBox and Alpine Linux. This page shows how to install bash shell in Alpine Linux using the apk command.

How do I install bash shell in Alpine Linux?

It is easy to have bash installed but this does not mean the symlinks to busybox are gone. The syntax is as follows with apk command
# apk update
# apk upgrade
# apk add bash

Sample outputs:

(1/5) Installing ncurses-terminfo-base (6.0-r7)
(2/5) Installing ncurses-terminfo (6.0-r7)
(3/5) Installing ncurses-libs (6.0-r7)
(4/5) Installing readline (6.3.008-r5)
(5/5) Installing bash (4.3.48-r1)
Executing bash-4.3.48-r1.post-install
Executing busybox-1.26.2-r5.trigger
OK: 14 MiB in 21 packages

How to install bash man pages and other docs

To install bash documentation, enter:
# apk add bash-doc
To install bash automatic command line completion install, run:
# apk add bash-completion
Sample session:

Fig.01: How to get bash working on Alpine Linux

How to set bash as login shell

To use bash as a shell just type bash:
$ bash
To login to alpine Linux LXD vm from host, enter:
$ lxc exec alpine-lxd-vm-name-here bash
One can change root shell to bash shell using the following method:
# vi /etc/passwd
Find user name and the default shell such as /bin/ash:

root:x:0:0:root:/root:/bin/ash 

Replace it with /bin/bash:

root:x:0:0:root:/root:/bin/bash

Customize bash shell

Here is a sample file:
cat ~/.bashrc
Sample outputs:

alias update='apk update && apk upgrade'
export HISTTIMEFORMAT="%d/%m/%y %T "
export PS1='u@h:W $ '
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
source /etc/profile.d/bash_completion.sh

See Customize the bash shell environments wiki page for more info.

Conclusion

You learned how to install bash shell on Alpine Linux along with documents, man pages and configure the bash shell as per your needs. I suggest you read bash man pages/docs here online for more info.

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...