If you’re looking for a lightweight Linux distribution, Alpine Linux might be a breath of fresh mountain air for you!
What Is Alpine Linux?
Alpine Linux is a Linux distro that aims for minimalism, both in terms of space and in scope, as well as for higher security. The default installation media is only 133MB. This is quite impressive given that some ISO files on other distros are designed more for DVDs and thumb drives. Alpine fits comfortably on a CD-R with room to spare.
Alpine Linux uses a technique called position-independent executables to randomize the location of programs in memory. This makes it difficult for an attacker to exploit quirks in the memory and take over a machine.
The distro is also minimalist in its configuration. It gets its small size by using the BusyBox suite to provide most of the utilities in one executable.
Alpine’s small size makes it suitable for people running containers, especially Docker.
Download: Alpine Linux
Installing Alpine Linux
Installing Alpine Linux is similar to installing any other Linux distribution. You grab the installation image and transfer it to your preferred media, and then reboot your machine.
Alpine’s minimalism applies to its installation process as well. You find yourself at the standard Linux text console. There’s no graphical installation here.
As for installation images, you have several choices on the download page, depending on how complete a system you want to install.
The Standard image is recommended for most people and includes the most commonly used packages. Get this one if you’re completely new to Alpine.
The Extended image is meant for specialized devices like routers that won’t get updated as much, so it has more packages than Standard.
If you want to install a very minimal system, get the Netboot image, which only includes the bare minimum to boot and connect to the network. You’ll then have to download any other required packages. This option is for those who really like to tailor systems to their requirements.
At installation, you log into the booted system as root. There’s no menu-driven system. All of the setup is done at the command line. If you’ve installed Arch Linux, this process will be familiar to you.
While Alpine doesn’t hold your hand very much, they’ve included some scripts that will walk you through the installation process. The most important is setup-alpine. The script will ask you things like your keyboard layout and time zone and will help you in partitioning your disk as well. You can just accept the defaults.
You can find more details on setting up Alpine on your machine in the documentation and the wiki. Some of the information might be out of date. You might try to install a package recommended in the documentation only to find out that it doesn’t exist in the repository.
Configure Alpine Linux
When you finally boot into your new Alpine installation, it’s still pretty bare, with just the text console and the shell. You’ll want to make some customizations to the default system to make it truly useful.
Set Up a Regular User
When you first install Alpine, the only user is root. You don’t want to run as root all the time. It’s a security risk and you might accidentally damage important system files.
To add another user, simply type:
You’ll replace “username” with the name of the user you want to use for login. The -h option specifies the home directory, while the -s option specifies the pathname for the shell, ash, which is the default shell for BusyBox and thus the shell installed in Alpine Linux. If you want to use another shell, you would change this option to the path to your preferred shell.
To set a password for the user, use the passwd command:
You’ll be prompted to set up a password for the user. Re-enter the password to confirm the process. Once this is done, you can log out of the root account and log in to your regular user account.
By default, when you want to run commands as root, you’ll use the su command:
The - option means to start a login shell as if you’d logged in to root directly. Type the root password when prompted, and you’ll then be presented with the # prompt which indicates you’re running as root. When you finish running your administrative commands, it’s best to leave the root session by typing logout or pressing Ctrl + D to get back to your regular session.
If you’re used to using sudo, the documentation has information on how to set it up.
Package Management
As with any other modern Linux distro, Alpine uses a package manager. They’ve created their own, called the Alpine Package Keeper, or APK.
Using APK is simple. If you’re used to using Apt on Debian or Ubuntu, it’s even simpler. It’s not apparent if it was deliberate, but many of the commands are identical.
To update the repository, just issue this command:
To upgrade your packages to the latest available, type:
To install a particular package, in this case, Vim, type:
To delete a package, type:
If any packages are no longer needed after removal, APK will automatically remove them. This differs from APT as you have to run the apt autoremove command to do the same.
Set Up a Desktop Environment
Unless you plan on installing Alpine as a server, you’ll probably want to install a graphical environment. Fortunately, Alpine supports the major window managers and desktop environments.
To set up X, Alpine provides the setup-xorg-base script. It’s similar to the installation process, where you run it and answer a few questions about your setup. In most cases, the configuration is automatic.
You’ll have to install your preferred window manager, desktop, file manager, etc. on your own. You’ll probably also want to install a display manager like LightDM as well. However, you’ll have to tell OpenRC to start it up automatically.
For example, to use LXDM;
Is Alpine Linux for You?
If you’re looking for something different than the usual crop of Linux distros, Alpine Linux is something worth considering. If you want a lightweight server OS for virtualization or containers, Alpine is the one to go for.
Although there are many lightweight Linux distributions available on the internet, you should find Alpine Linux suitable for all your needs.