Package Management Concepts
Contemporary distributions of Linux-based operating systems install software in pre-compiled packages, which are archives that contain binaries of software, configuration files, and information about dependencies. Furthermore, package management tools keep track of updates and upgrades so that the user doesn’t have to hunt down information about bug and security fixes.
Without package management, users must ensure that all of the required dependencies for a piece of software are installed and up-to-date, compile the software from the source code (which takes time and introduces compiler-based variations from system to system), and manage configuration for each piece of software. Without package management, application files are located in the standard locations for the system to which the developers are accustomed, regardless of which system they’re using.
Package management systems attempt to solve these problems and are the tools through which developers attempt to increase the overall quality and coherence of a Linux-based operating system. The features that most package management applications provide are:
- Package downloading: Operating-system projects provide package repositories which allow users to download their packages from a single, trusted provider. When you download from a package manager, the software can be authenticated and will remain in the repository even if the original source becomes unreliable.
- Dependency resolution: Packages contain metadata which provides information about what other files are required by each respective package. This allows applications and their dependencies to be installed with one command, and for programs to rely on common, shared libraries, reducing bulk and allowing the operating system to manage updates to the packages.
- A standard binary package format: Packages are uniformly prepared across the system to make installation easier. While some distributions share formats, compatibility issues between similarly formatted packages for different operating systems can occur.
- Common installation and configuration locations: Linux distribution developers often have conventions for how applications are configured and the layout of files in the /etc/ and /etc/init.d/ directories; by using packages, distributions are able to enforce a single standard.
- Additional system-related configuration and functionality: Occasionally, operating system developers will develop patches and helper scripts for their software which get distributed within the packages. These modifications can have a significant impact on user experience.
- Quality control: Operating-system developers use the packaging process to test and ensure that the software is stable and free of bugs that might affect product quality and that the software doesn’t cause the system to become unstable. The subjective judgments and community standards that guide packaging and package management also guide the “feel” and “stability” of a given system. In general, we recommend that you install the versions of software available in your distribution’s repository and packaged for your operating system. If packages for the application or software that you need to install aren’t available, we recommend that you find packages for your operating system, when available, before installing from source code.
The remainder of this guide will cover how to use specific package management systems and how to compile and package software yourself.
Advanced Packaging Tool (APT)Permalink
You may already be familiar with apt-get, a command which uses the advanced packaging tool to interact with the operating system’s package system. The most relevant and useful commands are (to be run with root privileges):
- ‘apt-get install package-name(s)’ - Installs the package(s) specified, along with any dependencies.
- ‘apt-get remove package-name(s)’ - Removes the package(s) specified, but does not remove dependencies.
- ‘apt-get autoremove’ - Removes any orphaned dependencies, meaning those that remain installed but are no longer required.
- ‘apt-get clean’ - Removes downloaded package files (.deb) for software that is already installed.
- ‘apt-get purge package-name(s)’ - Combines the functions of remove and clean for a specific package, as well as configuration files.
- ‘apt-get update’ - Reads the /etc/apt/sources.list file and updates the system’s database of packages available for installation. Run this after changing sources.list.
‘apt-get upgrade’ - Upgrades all packages if there are updates available. Run this after running apt-get update. While apt-get provides the most often-used functionality, APT provides additional information in the apt-cache command.
- ‘apt-cache search package-name(s)’ - If you know the name of a piece of software but apt-get install fails or points to the wrong software, this looks for other possible names.
- ‘apt-cache show package-name(s)’ - Shows dependency information, version numbers and a basic description of the package.
- ‘apt-cache depends package-name(s)’ - Lists the packages that the specified packages depends upon in a tree. These are the packages that will be installed with the apt-get install command.
- ‘apt-cache rdepends package-name(s)’ - Outputs a list of packages that depend upon the specified package. This list can often be rather long, so it is best to pipe its output through a command, like less.
- ‘apt-cache pkgnames’ - Generates a list of the currently installed packages on your system. This list is often rather long, so it is best to pipe its output through a program, like less, or direct the output to a text file. Combining most of these commands with apt-cache show can provide you with a lot of useful information about your system, the software that you might want to install, and the software that you have already installed.
Aptitude
Aptitude is another front-end interface for APT. In addition to a graphical interface, Aptitude provides a combined command-line interface for most APT functionality. Some notable commands are:
Using dpkg
Apt-get and apt-cache are merely frontend programs that provide a more usable interface and connections to repositories for the underlying package management tools called dpkg and debconf. These tools are quite powerful, and fully explaining their functionality is beyond the scope of this document. However, a basic understanding of how to use these tools is useful. Some important commands are:
- ‘dpkg -i package-file-name.deb’ - Installs a .deb file.
- ‘dpkg –list search-pattern’ - Lists packages currently installed on the system.
- ‘dpkg –configure package-name(s)’ - Runs a configuration interface to set up a package.
- ‘dpkg-reconfigure package-name(s)’ - Runs a configuration interface on an already installed package
Fedora and CentOS Package Management
Fedora and CentOS are closely related distributions, being upstream and downstream (respectively) from Red Hat Enterprise Linux (RHEL). Their main differences stem from how packages are chosen for inclusion in their repositories.
CentOS uses yum, Yellowdog Updater, Modified, as a front end to interact with system repositories and install dependencies, and also includes a lower-level tool called rpm, which allows you to interact with individual packages.
Starting with version 22, Fedora uses the dnf package manager instead of YUM to interact with rpm. DNF supports many of the same commands as YUM, with some slight changes.
Note: Many operating systems aside from RedHat use rpm packages. These include OpenSuSE, AIX, and Mandriva. While it may be possible to install an RPM packaged for one operating system on another, this is not supported or recommended, and the results of this action can vary greatly.
How about macOS?
Homebrew is package manager for Macs which makes installing lots of different software like Git, Ruby, and Node simpler. Homebrew lets you avoid possible security problems associated with using the sudo command to install software like Node. Homebrew has made extensive use of GitHub to expand the support of several packages through user contributions. In 2010, Homebrew was the third-most-forked repository on GitHub. In 2012, Homebrew had the largest number of new contributors on GitHub. In 2013, Homebrew had both the largest number of contributors and issues closed of any project on GitHub. Homebrew has spawned several sub-projects such as Linuxbrew, a Linux port now officially merged into Homebrew; Homebrew Cask, which builds upon Homebrew and focuses on the installation of GUI applications and “taps” dedicated to specific areas or programming languages like PHP.
macOS Requirements
A 64-bit Intel CPU macOS 10.12 (or higher) Command Line Tools (CLT) for Xcode A Bourne-compatible shell for installation (e.g. bash or zsh)
Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
How to Update Homebrew
New versions of Homebrew come out frequently, so make sure you update it before updating any of the other software components that you’ve installed using Homebrew. * In Terminal type
brew update
How to Uninstall Homebrew
Open the Terminal app Type
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)
This downloads and runs the uninstaller script. Follow the instructions and Homebrew will be removed from your computer.
List installed packages
We can get a list of all the installed packages on a Debian / Ubuntu server by issuing:
$ sudo dpkg --get-selections
Ubuntu server by issuing:
$ apt list --installed
on macOS
$ brew list
On RPM systems:
$ yum list installed
On BSD systems:
$ pkg_version
It is good practice to save this file as it can be useful when migrating, so we pipe it into a file:
$ dpkg --get-selections > ~/package_list
#yum list installed
#pkg_version
To search for a specific package run:
$ dpkg --get-selections | grep <package>
$ yum list installed "package_name"
Search packages
On Ubuntu systems:
apt search <package-name>
$ apt search firefox
$ apt search ^firefox
On macOS systems:
brew search <package-name>
$ brew search firefox
$ brew search /^firefox/
\^ means regular expressions start of the line.
Install packages
Install single packages:
On Ubuntu systems:
apt install <package-name>
On macOS systems:
brew install <package-name>
Install multiple packages:
On Ubuntu systems:
apt install <package-name> <package-name> ...
On macOS systems:
brew install <package-name> <package-name> ...
Install specific version
Search version
On Ubuntu systems:
$ apt-cache policy <package-name>
On macOS systems:
$ brew search <package-name>
Install specific version
On Ubuntu systems:
$ apt install firefox=68.0.1+build1-0ubuntu0.18.04.1
On macOS systems:
$ brew install firefox@68.0.2
Let’s install test package!
On Ubuntu systems:
$ apt install screenfetch
On macOS systems:
$ brew install screenfetch
screenfetch
Let’s install prerequisite packages
On Ubuntu systems:
$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl vim
On macOS systems:
$ brew install openssl readline sqlite3 xz zlib
This manual was adapted from Linode. Linode is the BEST knowledge site ever.