Shell management

From Alpine Linux
Revision as of 16:31, 21 July 2025 by Prabuanand (talk | contribs) (converted list to table)

The default shell used by Alpine Linux is the BusyBox variant of the ash shell. This page explains how to use the default shell and various ways to change the default shell in Alpine Linux.

Ash shell

Alpine Linux uses Busybox Ash shell for its default shell. It is a standard POSIX shell derived from Debian Ash variant.

One's ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an ~/.ashrc or ~/.config/ash/ashrc file, reviewing it carefully for syntax/cli variants against that of Ash shell.

Tip: Use checkbashisms script to perform basic checks for the presence of bashisms in scripts and help remove them.

If aliases are required only for login shells(tty), no additional steps are involved. For non login, interactive shells refer to Setting alias section.

Setting alias

When using Ash shell, in order to use aliases for both login and non login shells, use ENV environment variable to refer the aliases file. This works as long as the shell is interactive.

  1. First create the file /etc/profile.d/profile.sh as follows:

    Contents of /etc/profile.d/profile.sh

    if [ -f "$HOME/.config/ash/profile" ]; then . "$HOME/.config/ash/profile" fi
  2. Next create the file ~/.config/ash/profile as follows:

    Contents of ~/.config/ash/profile

    export ENV="$HOME/.config/ash/ashrc"
  3. Now aliases can be added in the file ~/.config/ash/ashrc:

    Contents of ~/.config/ash/ashrc

    alias a=alias alias c=clear alias l='ls -lh'

Available shells

Most of the popular shells are available in Alpine Linux repositories as can be seen from the below list.

Name URL Remarks
bash https://www.gnu.org/software/bash/bash.html The GNU Bourne Again shell
zsh https://www.zsh.org/ Very advanced and programmable command interpreter
fish https://fishshell.com/ Modern interactive commandline shell
dash http://gondor.apana.org.au/~herbert/dash/ Small and fast POSIX-compliant shell
oksh https://github.com/ibara/oksh Portable OpenBSD ksh, based on pdksh
loksh https://github.com/dimkr/loksh A Linux port of OpenBSD's ksh
yash https://magicant.github.io/yash Yet another shell
tcsh https://github.com/tcsh-org/tcsh extended C-shell
nsh https://github.com/nuta/nsh A command-line shell like fish, but POSIX compatible
elvish https://elv.sh Friendly and expressive Unix shell
nushell https://www.nushell.sh A new type of shell
murex https://murex.rocks/ Intuitive, typed and content aware shell

To install any of the above shells, say for eg: bash shell:

# apk add bash bash-completion

Change default shell

There are various ways to change the default shell in Alpine Linux. You can revert back to ash shell at anytime with the same steps.

Note: After performing the below step, you need to log out and login again for these changes to take effect.

By hand

Edit /etc/passwd manually using an editor of your choice. An example line for a user named user is:

Contents of /etc/passwd

... user:x:1000:1000:user:/home/user:/bin/ash ...

Change /bin/ash to point to the path of a shell from /etc/shells. Take care to not delete/mangle the line, as it would make you unable to log in again. The user should be the user you are changing the default login shell for.

Using chsh command

To use chsh command, install the shadow package:

# apk add shadow

And use chsh:

# chsh username

Now enter the path for the shell you want to use (e.g /bin/zsh) and press Enter to confirm this change. The shell should exist in /etc/shells.

See also