Ubuntu Packages and Package Manager

Ubuntu Packages and Package Manager

·

6 min read

📱 Packages

In Linux, everything except the kernel is a package. It's a piece of software designed to handle a specific task. That can be a driver for hardware, a utility like bash, or an application like a browser or text editor.

Every package contains:

  • binaries or the executable programs

  • metadata files (version, dependencies, signatures etc)

  • documentation and manuals

  • configuration files

Keeping these things organised allows automation of the process of installing or removing a package, which is the task of a package manager.

Package managers

Different Linux versions have different package managers, and it's always a good idea to stick to the default package manager of your distribution. Ubuntu is a Debian-based sytem and uses dpkg at its lowest level, and apt-get / apt ("Advanced Packaging Tool" and its newer, slightly different version) as a sort of front-end that makes it easier to handle. A package for Debian has the file extension .DEB.

Besides installation/deinstallation of software, other jobs of the package manager are:

  • verifying the integrity of a package

  • check for hardware compatibility before installation

  • updates and upgrades

  • keeping track of a list of all installed packages and the dependency tree

Dependencies

Most packages depend on others / are built on top of them. When installing a package, all dependencies need to be installed, too - in the version that the package requires. Packages also receive updates on a regular basis, dependencies/versions might change. When there's dozens or even hundreds of dependencies, it would be almost unmanageable for a human to install them all manually, in any case, it would be most tedious. Maintaining a Linux system before the arrival of package managers must've been quite a task.

To see a list of all dependencies installed (on a system using dpkg):

dpkg -l

To only query for their total number:

dpkg -l | wc -l

On my super-fresh system, that's about 1660 packages.

To view detailed information about a package, including

  • version number

  • maintainer

  • location of repository

  • dependencies

  • name and location of all configuration files:

dpkg -s <package-name>
# or
apt show <package-name>

Repositories

A repository is the location of a package. In most cases, that would be a server on the internet, but it can also be a USB stick or some other sort of storage.

Ubuntu's repositories are divided into four categories:

  • Main (Canonical-supported free and open-source software)

  • Universe (Community-maintained free and open-source software)

  • Restricted (Proprietary drivers for devices)

  • Multiverse (Software restricted by copyright or legal issues)

If you want to get software from a repository, you first have to add it to the sources.list.

To print all sources that you're currently getting software from:

cat /etc/apt/sources.list

After a fresh installation, you'll see the above mentioned four Ubuntu repos. If you need a package from a different party, you first have to add their repository to the list of sources (find a how-to link at the end of this article).


📱 Advantages

The advantages of installing software through the command line / a package manager become obvious the first time you use it.

To install Firefox through the traditional way on a Windows PC, I have to go to their website, download a file and execute it. I can't be 100% sure if I've really been on Firefox's website, or if I'm accidentally installing evilCoder9's malware.

Installing it via command line is as easy as typing one line: sudo apt install firefox.

Since the package manager will verify the integrity before installation, I can be sure that it's coming from the official repository and that it hasn't been tampered with while travelling to my computer.


📱 Installing Packages

The standard command to access the package manager is apt.

The first thing before installing a new package is usually to check if the current system is up-to-date. You do that with:

sudo apt update

This won't install any updates yet, but it'll scan your package versions and compare them with their respective repositories to update the package information. It'll then give you some feedback about available updates. You can first check whether there's any version conflicts before possibly breaking something with:

sudo apt list –upgradable

To actually install the updates, run

sudo apt upgrade

Once the system is up-to-date, it's ready for installation of new packages.

To search for a package in the terminal:

sudo apt search "search-term"

To see more detailed information about a certain package:

sudo apt show <package-name>

To install the package:

sudo apt install <package-name>

To re-install a package (if you think you've broken something):

sudo apt reinstall <package-name>

To remove a package (but keep user-configured files):

sudo apt remove <package-name>

Remove package (including user-configured files):

sudo apt purge <package-name>

Removing a package doesn't remove all the dependencies that were installed with it, but you can remove unused packages with:

sudo apt autoremove

apt and apt-get aren't 100% the same, but for a beginner, it doesn't seem to make a huge difference ("if apt doesn't work, just try apt-get").


📱 Snap Packages

Snap Packages are a relatively recent addition. They're standalone applications that bring all of their dependencies with them, and run in their own isolated environment.

Having no external dependencies is a great advantage, because you won't run into a situation where two applications require different versions of the same dependency. I've not yet encountered such a conflict, but from what I've read so far, it's definitely a situation that you want to avoid.

Also, they offer increased security. They auto-update almost immediately, and due to their encapsulation, they can't interfere with any system files.

The trade-off is a larger package size, and maybe you'll end up having multiple versions of the same dependency, each isolated in their own snap package. But considering that disk space isn't really an issue on your usual average computer, I suppose that's a small price to pay, if it in turn completely avoids potential dependency hell.

To search for and install a package, you can either go to the Snapcraft App Store, or use the CLI:

Searching for a package:

snap find <name-of-software>

If you search for example for Firefox, you'll get a list of matches (the browser itself and some additional third-party packages).

To install it, use the string from the leftmost column ("Name"):

sudo snap install <package-name>

To remove a package:

sudo snap remove <package-name>

To see a list of all installed snap packages:

snap list

📱 Resources

Ubuntu: Repositories/CommandLine

Ubuntu: List of Packages

A Beginners Introduction to Linux Package Managers

How to Install any Ubuntu Package using Apt

How to Work with Snap Packages on Linux


📱 Thanks for reading!

If you find any errors or have additions, questions or just want to say hi, please leave a comment below, or get in touch via my website jsdisco.dev or Twitter.
Keep calm & code 👋