Skip to content

Linux Software and Packages

Installing software on Linux may be a bit different than what you are used to. For example, you may be used to opening a webpage, downloading an installer, and running it to install a certain package. Alternatively, you may be used to installing games from a store like Steam. Gaming on Linux is beyond the scope of this book, but if you are into gaming, Steam and GOG, among others, do have Linux-compatible games.

Thankfully, most Linux distributions make installing software ridiculously simple. Not all software is available for Linux, but there is plenty of very high-quality software available for free, both as in beer, and speech. That means that not only do you not have to pay for it (but do support the authors when you can if they take donations), but you also have certain rights, e.g. as those granted by the GPL and other free license.

In this chapter, we will look at how software is commonly packaged, some common package managers, and how to build software from source.

Dynamic vs static linking

When writing software in a compiled languages like C or C++, it is necessary to compile the code from source to a binary executable. Just like Python can use modules, C/C++ can use libraries to avoid needing to write a lot of low-level code.

Libraries can be fully included in a binary executable through static linking, or they may be referenced through dynamic linking. Static linking means that the code in the library is copied into the binary executable, whereas dynamic linking means that the library code exists in separate files.

You may be familiar with this in Windows with dynamically linked libraries, or DLL files. In Linux, those libraries are commonly called shared libraries, and end with a .so extension. The main advantages of using shared libraries are that executable programs are smaller, but also the Kernel can cache shared libraries, which can improve application performance when many programs rely on the same libraries.

For that reason, libraries are often packaged separately from the executable. For example, the GNU core utilities on Arch Linux are provided by the coreutils package. This package depends on the glibc package, which provides the GNU implementation of the standard C library.

Shared libraries are commonly found in /usr/lib/ or /usr/lib64/ (which is often nothing more than a symlink). If you install multi-architecture libraries to allow running executables built for 32-bit architectures on a 64-bit system, you may also find a /usr/lib32/ directory. Note: this may vary from one distro to another.

Standard libraries

While glibc is probably the most commonly used C standard library implementation, there are some alternatives with different features, or released under different licenses.

One common alternative to glibc is musl, which is smaller, and faster, but may not be perfectly compatible with glibc.

While most large distros such as Arch Linux and Ubuntu use glibc, Alpine Linux uses musl. That means that some packages, such as VS Code, may not work with Alpine Linux, and performance of the same applications may vary on different systems.

Package managers

Most distros have their own package managers and software repositories. A software repository contains a collection of packages, and is maintained by package maintainers. Their job is to build packages from source based on the distro's packaging requirements and release process. For example, Arch Linux is a rolling-release distro, meaning that software is commonly updated to the latest version, and there are no versioned Arch Linux releases (except for the installer). A new installation image is generated regularly, but there is no specific version. On the other hand, Ubuntu has a new version released roughly every six months, and software versions may differ between them. Software packaged for Ubuntu 20.04, released in April 2020, is generally older than software packaged for Ubuntu 22.04, which was released two years later.

Package managers are programs that allow you to manage the packages that are installed on your system. They can be used to install, upgrade, or remove software. They generally manage the packages' dependency trees, so the command to install one package may install many others. The package manager you use depends on your distro of choice.

Package managers typically keep a local copy of the available packages database. This needs to be frequently updated to ensure you install the latest version of a package or to install software updates. Note: updates may fix important security issues, so you should keep your system up-to-date as much as possible.

Note that due to file permissions, and for security purposes, managing system packages typically requires root privileges.

Arch Linux

The official Arch Linux package manager is pacman, which is used to install packages from the official Arch Linux repositories.

To install a package, you can use the -S argument followed by the package name. Note that you may pass multiple package names to install more than one package.

$ sudo pacman -S neovim # installs the neovim package and its dependencies

You can synchronize the package database with the official repositories with the -S -y arguments, commonly passed as one argument since they are short flags.

$ sudo pacman -Sy

This is commonly used with the -u flag to update all installed packages. This command synchronizes the package database and applies all the latest updates in one go.

$ sudo pacman -Syu

You can also use -R to remove packages. For example, you could uninstall VS Code as follows, since we all know neovim is vastly superior:

$ sudo pacman -R code

Official repositories

As of this writing, the most important repositories are core, which contains the most important packages for running a base Arch install, and extra which contains tons of software like desktop environments, web browsers, media players, etc. Repositories can be enabled or disabled by editing the /etc/pacman.conf file.

You can also enable the multilib repository if you would like to run 32-bit software on a 64-bit system.

Searching for packages

You can search for packages using the pacman utility with the -Ss flags, e.g.:

$ pacman -Ss neovim

As this does not modify the system's state, it does not require root privileges.

You can also search the package database on the Arch Linux website.

Arch User Repository

If some package you want to install is not available in the official repositories, you may be able to install it from the Arch User Repository, (AUR). These packages are not maintained by the Arch package maintainers, but by the community. Note: as these packages are not officially endorsed or vetted by the Arch maintainers, it is theoretically possible for users to submit nefarious packages.

Some packages may not be available in the official repositories due to licensing issues, e.g. Google Chrome.

pacman does not support installing packages from the AUR, but you can use one of the many helpers available. I use pikaur, as it is written in Python and I can hack away at it (and other jokes I tell myself), but yay is also a popular option.

Pro-tips

By default, pacman will keep all old packages in /var/cache/pacman/pkg/. It's a good idea to keep some older versions in case you need to downgrade a package at some point, but this directory may grow to an unreasonable size after some time. You can mitigate this by installing the pacman-contrib package, and enabling the paccache.timer unit.

$ sudo pacman -S pacman-contrib
$ sudo systemctl enable --now paccache.timer

For fun, you can also add the ILoveCandy option to your /etc/pacman.conf file. This will replace the default progress bar with a Pac-Man themed one. Waka waka!

Meta packages and package groups

Meta packages and package groups can be used to install many related packages. For example, you could install KDE Plasma with sudo pacman -S plasma-meta. Both meta packages and package groups work fairly similarly, with some minor differences as covered in the Arch wiki.

Ubuntu

Ubuntu, and other distros based on Debian, uses the apt package manager.

To install packages, you can use the install argument followed by one or more package names. For example, you can install the guake drop-down terminal as follows:

$ sudo apt install guake

Note: guake is good to use with the Gnome desktop environment, but if you use Kubuntu, you may want to use yakuake instead. Desktop environments will be covered in the _GUIs_ section.

You can synchronize the package database with the active repositories with the update argument:

$ sudo apt update

You can upgrade all installed packages with the upgrade argument:

$ sudo apt upgrade

Upgrading releases

Since Ubuntu and its derivatives are not rolling-release, you may occasionally need to perform a full system update by updating to a new release with the do-release-upgrade command:

$ sudo do-release-upgrade

Alternatively, if you are using a GUI, you can use the Ubuntu software updater.

Official repositories

The official repositories are defined in the /etc/apt/sources.list file. The four main repositories (which may not all be enabled on your system) are:

  • Main: software that is supported by Canonical.
  • Universe: software that is maintained by the community.
  • Restricted: proprietary drivers that is not built into the Linux kernel.
  • Multiverse: extra software that may have copyright or legal issues.

Extra repositories

You can add extra repositories with the add-apt-repository command, or by adding them to .list files in the /etc/apt/sources.list.d directory. An example will be provided in the chapter on Docker.

Searching for packages

You can search for packages using the apt package manager with the search argument, e.g.:

$ apt search neovim

You can also use the online Ubuntu Packages Search.

Alpine Linux

Alpine Linux uses the Alpine Package Keeper, or apk, as a package manager.

To synchronize the package database with the active repositories, we can use the update argument:

$ sudo apk update

To search for packages, use the search argument:

$ sudo apk search neovim
fzf-neovim-0.52.0-r3
neovim-0.10.0-r1
neovim-doc-0.10.0-r1

To install packages, use the add argument with the package name:

$ sudo apk add neovim

Note: we omit the package version from the add command, and use neovim, rather than neovim-0.10.0-r1.

To update packages, first synchronize the package database with the active repositories, then use the upgrade argument:

$ sudo apk update
$ sudo apk upgrade

To remove packages, use the del argument, which works similarly to the add argument:

$ sudo apk del emacs

(My apologies to emacs users for this example... I simply prefer neovim.)

Flatpak and Snap

Python packages

Please see the Python on Linux chapter to learn how to manage and install Python packages.