Software Development in Linux-Package Management system

Mostafa Farrag
Hydroinformatics
Published in
13 min readAug 27, 2023

--

Unix-like operating systems provide a centralized method for discovering and installing software, which is commonly referred to as package management. Software distribution often involves the use of packages stored in repositories. These packages encompass essential elements of an operating system, including shared libraries, applications, services, and documentation.

Most commonly used package managers in Linux

Package managers handle dependencies, which are other software packages or libraries required for a particular application to function correctly. When installing a package, the package manager automatically identifies and installs any necessary dependencies, streamlining the installation process and ensuring that the software has all the required components to run. Package managers typically work with specific package formats, such as .deb for Debian-based distributions and .rpm for Red Hat-based distributions. These formats encapsulate the software, including executable files, libraries, configuration files, and metadata required for installation. The Package managers also ensure consistent installations and upgrades by following predefined procedures. They maintain a record of installed packages and track any modifications made to the system to facilitate proper upgrades and removals.

Illustration for the role of the package manager

Package management systems often offer additional functionality, such as package searching, package information display, automatic updates, rollbacks to previous package versions, and the ability to create custom software repositories. Package management can be performed through command-line tools (e.g., apt, yum, dnf) as well as graphical user interfaces (GUIs) provided by package managers. GUI tools offer a more user-friendly approach to managing packages and repositories.

In this article, I will go through some of the most commonly used package managers that I have personally used. You don’t need to know all of these package managers, but in some cases, you will find yourself in a situation where you are following an online instruction that uses this tool or that a package is only available in these package managers.

So this article will go through the following package managers in Linux

  • Debian package (DPKG)
  • Advanced Package Tool (Apt)
  • Snap
  • Homebrew
  • Wine
  • Aptitude
  • Synaptic

Earlier, I posted some articles on Medium about software development in Linux. The first article explained how to install WSL (Windows Subsystem in for Linux), some of the settings you need to configure to reach your file on your Windows file system, and also some terminal commands that you will use frequently.

In the second article, I installed miniconda in WSL and explained how to integrate it with Pycharm.

And now lets start with the first package manager.

DPKG

In Linux, dpkg is a low-level package management tool used in Debian-based distributions such as Ubuntu, Debian, and Linux Mint. It provides functionality for managing individual software packages in the form of .deb files.

dpkg is responsible for installing, configuring, removing, and querying individual Debian packages. It operates at a lower level than higher-level package managers like APT (Advanced Package Tool) and directly interacts with the package files.

  • dpkg handles the configuration of packages. When a package is installed or upgraded, dpkg runs pre- and post-installation scripts included with the package, allowing for customization or setup steps related to the software being installed.
  • Offline package management: dpkg operates offline and does not handle automatic dependency resolution. If a package requires other packages to be installed, dpkg will report unresolved dependencies and prompt the user to manually install the missing dependencies.
  • dpkg is primarily used through the command line, providing a set of commands to manage packages. It does not interact with remote repositories but works with local package files.

Search

You can query package information with commands like dpkg -l to list installed packages, and you can filter the result of the previous command using the grep with a specific word

  • For example, to list all the installed packages that start with the word “python”
dpkg -l | grep python
  • dpkg -s package_name to display detailed information about a specific package
dpkg -s python3
  • dpkg -L package_name to list the files installed by a package.
dpkg -L python3

Install

You can use dpkg to install packages from .deb files. The command dpkg -i package.deb installs a specific package. It unpacks the package contents, configures the software, and registers the package as installed on the system.

dpkg -i <package-name.deb>
  • You can find any package you want on the debian.org website

Uninstall

  • dpkg allows you to remove installed packages using the command dpkg -r package_name. This removes the package files from the system and performs any necessary cleanup.
dpkg -r <package-name>

While dpkg is a powerful tool for working with individual packages, it is typically used in conjunction with higher-level package managers like APT, which provide more advanced features such as dependency resolution and repository management. APT builds on top of dpkg to offer a more comprehensive package management system.

APT

APT (Advanced Package Tool) is a command-line package management tool used in Debian-based Linux distributions, including Ubuntu, Linux Mint, and Debian itself. It is the primary package management system for these distributions and provides a straightforward and efficient way to handle software packages.

Search

  • APT provides commands to search for packages based on keywords or descriptions. The apt search command helps find relevant packages. You can also obtain detailed information about a specific package, including its description, version, and dependencies, using the apt show command.
sudo apt search <package-name>
  • If you searched for a package, and the search resulted in nothing, it means that the package does not exist in the list of repositories defined for the apt tool.
  • Now, after adding the repository that has the package, and searching for the package again, the search will give only one repository, which is what you have just added.
  • Some packages are available in many repositories like postgresql

Add repository

  • The APT configuration file responsible for repository management is /etc/apt/sources.list (or a file in the /etc/apt/sources.list.d/ directory). Open the file using a text editor with administrative privileges.
  • If you opened the /etc/apt/sources.list file, It will look like the following picture.
  • The links above you can find them in many websites like debian.org or pkgs.org, for example, when searching for the 7zip package in debian.org, and choosing the architecture you want, you will get the following.
7zip package in the debian.org website (Link)
  • To add a repository, use the add-apt-repository command, followed by the repository path.
sudo add-apt-repository <repository-path>
  • To add a repository, you have to add also the GPG key for the repo; otherwise, the apt tool will try to compare the signature of the repository, and once it does not find the GPG key to compare with, it will complain that the repository is not signed, and, therefore, not secured, and disable it.
  • To add the GPG key (in this example, we are installing sublime-text), use the curl command
curl -fsSL https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add
  • Then, after adding the GPG key, add the repository.
  • Now, the apt tool could compare the repo signature to the GPG key.

Install

  • apt install command searches for the dependencies, resolves them, and installs the package.
sudo apt install sublime-text

Update/Upgrade

apt update:

  • The apt update command updates the package lists from the configured repositories. It retrieves the latest information about available packages, their versions, and dependencies.
  • It does not install or upgrade any packages but rather fetches the latest package information to ensure that your system has up-to-date knowledge of the available software.
  • This command is used to refresh the local package cache and synchronize it with the remote repositories.
sudo apt update

apt upgrade:

  • The apt upgrade command upgrades the installed packages to their latest available versions.
  • It uses the updated package lists obtained from apt update to identify the packages that have newer versions and then installs those updates.
  • apt upgrade also handles package dependency resolution, ensuring that any required dependencies for the upgrades are met.
  • This command is used to apply available updates and keep the installed packages on your system current.
sudo apt upgrade

Remove/Purge

  • To remove a package, you have two options, the remove and the purge commands.
  • The remove command removes the package only, but the configuration files stay in your system, while the purge command will remove everything.
  • If you plan to reinstall the package later and want to preserve custom configurations, you may use apt remove. However, if you want to completely remove the package and start fresh, including all configurations, apt purge is the appropriate command to use.
sudo apt install purge <package-name>

Snap

snapcraft.io

Conical Snapcraft package managers

Snapcraft.io is a platform and a set of tools provided by Canonical Ltd. for building, packaging, distributing, and updating software applications in a format known as “snaps.” Snaps are containerized software packages designed to work across various Linux distributions, providing a consistent and isolated environment for applications to run.

Conical Snapcraft

Install Snap

sudo apt install snapd

Install packages using Snap

sudo snap install <appname>
  • Or download the snap package, which you will get a file with a .snap extension
snap install <package_name.snap>
  • To list all the packages installed by snap
snap list

Remove

  • To remove a package installed by snap
sudo snap remove <package_name>

Snap package names are case-sensitive. Make sure you enter the correct package name when using the snap remove command.

Update

sudo snap refresh <package_name>

Homebrew

Homebrew is actually a package manager specifically designed for macOS and Linux-based systems. It’s not typically used on Ubuntu because Ubuntu has its own package manager called “apt” (Advanced Package Tool), which is the standard way to install and manage software on Ubuntu and other Debian-based distributions; however, you can use it also to install packages in Linux, in case there is a package you want to install it and it is only available to be installed using homebrew.

Homebrew package manager for macOS
  • To search for packages that you can install by homebrew, you can visit the brew.sh website and use the search bar.

Install Homebrew

  • The following line will install homebrew directly from GitHub.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Copy and paste the above command to your terminal and follow the instructions that appear in the screen.

At the end of the installation, you will get the following.

End of installation screen and instructions to add Homebrew to PATH
  • Now we need to add Homebrew to the PATH environment variable, and to do that; You have to copy this command from the screen that appeared at the end of the installation shown in the previous picture.
Add Homebrew to PATH
  • Sometimes, Homebrew complains about some missing dependencies, and all you need to do is to install the “build-essential”
sudo apt-get install build-essential
Installing build-essential package using apt

Install a package

brew install <package-name>

Uninstall a package

brew uninstall <package-name>
  • For all the commands in brew you can always use the --help.

Wine

Wine is a compatibility layer that allows you to run Windows applications on non-Windows operating systems like Linux, macOS, and FreeBSD. It provides a way to execute Windows software without the need for a full Windows operating system by translating Windows API calls into equivalent calls that the host operating system can understand.

sudo apt install wine64
  • Once Wine is set up, you can simply double-click on a Windows executable file (.exe) to launch it. Wine will translate the necessary Windows API calls into Linux-compatible calls, allowing the application to run.
  • It’s important to note that while Wine is a powerful tool, not all Windows applications will work flawlessly, especially those that rely on specific Windows features that aren’t fully implemented in Wine. In such cases, you might need to seek alternatives or use virtualization or dual-boot setups to run Windows natively.

Aptitude

aptitude is a command-line package management tool available on Ubuntu and other Debian-based Linux distributions. It provides a text-based interface for managing software packages, similar to the more commonly used apt and apt-get commands.

  • aptitude offers several features that can make package management tasks more efficient and user-friendly.
  • aptitude is not as widely used as apt or apt-get in recent years, partly due to the popularity of these other commands and their integration with various package management tools and workflows. However, if you prefer a more interactive approach to package management and enjoy the features offered by aptitude, it's still a viable option on Ubuntu systems.
  • https://wiki.debian.org/Aptitude

Install aptitude

sudo apt install aptitude

Install a package

aptitude install <pkg_name>
  • For all the commands in aptitude, you can always use the — help.

Synaptic

Synaptic is a graphical package management tool for Debian-based Linux distributions, including Ubuntu. It provides a user-friendly interface for managing software packages on your system. Synaptic serves as an alternative to the command-line package management tools like apt, apt-get, and aptitude, offering a visual and intuitive way to install, remove, upgrade, and manage software.

  • You can install Synaptic using the following command:
sudo apt install synaptic
  • If you are using WSL to launch the tool, type the following
sudo synaptic
Synaptic GUI launched from a WSL terminal
  • Using Synaptic from Ubuntu Linux.
  • You can use the synaptic GUI to search, install, upgrade, and remove packages.
  • Synaptic is a handy tool, especially for users who prefer a graphical approach to software management. However, keep in mind that the software landscape has evolved, and some newer users might find the command-line tools or graphical software centers more convenient for their needs.

Summary

Package managers are essential tools that streamline the process of installing, updating, and managing software on Ubuntu Linux and other Linux distributions. They ensure that software installations are organized, dependencies are handled seamlessly, and updates are conveniently administered. Several package managers cater to different needs, each contributing to the efficiency of software management in the Linux environment. Some prominent package managers used in Ubuntu Linux include dpkg, apt, Homebrew (primarily for macOS but also available on Linux as Linuxbrew), Snap, Wine, aptitude, and Synaptic.

  • dpkg At the core of package management, dpkg is a low-level tool that deals with individual Debian package files (.deb). It performs installations, removals, and queries, and it manages package configurations.
  • apt: ( Building upon dpkg, apt ( (Advanced Package Tool) is a high-level package manager for Ubuntu and other Debian-based systems. It simplifies the management of dependencies, offering automatic updates, dependency resolution, and easy package retrieval from repositories.
  • Homebrew: Originally designed for macOS, Homebrew is a package manager that’s also available as Linuxbrew on Linux systems. It provides a simple way to install, manage, and update software packages, even though it’s not as prevalent in the Linux ecosystem as on macOS.
  • Snap: Snap is a modern package management system for Linux distributions, including Ubuntu. It uses containerization to ensure applications run consistently across different distributions, offering automatic updates, enhanced security, and isolation from the system.
  • Wine:Though not a traditional package manager, Wine allows Linux users to run Windows applications on their systems without requiring a Windows operating system. It translates Windows API calls into Linux-compatible ones, enabling Windows software to function on Ubuntu.
  • aptitude A text-based package manager, aptitude provides an interactive interface for package management, making it user-friendly and convenient for those who prefer a visual approach.
  • Synaptic: Synaptic is a graphical front-end for apt, offering a visual interface for managing packages. It simplifies tasks like package installation, removal, and upgrades, particularly for users who prefer GUI tools.

These package managers collectively form the backbone of software management in Ubuntu Linux, offering diverse options to cater to different preferences and needs. From command-line aficionados to those who favor graphical interfaces, Ubuntu users have a range of tools at their disposal to ensure a smooth and efficient software experience.

References

[1] Getting Started with Windows Sub System for Linux (WSL)-Installation & Command Lin, ehttps://mafarrag.medium.com/getting-started-with-windows-sub-system-for-linux-wsl-installation-68d8bf15175c

[2] Software Development in Linux-Install miniconda in WSL, https://medium.com/hydroinformatics/software-development-in-linux-install-miniconda-in-wsl-27e809a0c064

[3] Debian packages, https://www.debian.org/distrib/packages

[4] Packages for Linux and Unix, https://pkgs.org/

--

--