Most modern Unix-like operating systems offer a centralized mechanism for finding and installing software. Software is usually distributed in the form of packages, kept in repositories. Working with packages is known as package management. Packages provide the core components of an operating system, along with shared libraries, applications, services, and documentation.
A package management system does much more than one-time installation of software. It also provides tools for upgrading already-installed packages. Package repositories help to ensure that code has been vetted for use on your system, and that the installed versions of software have been approved by developers and package maintainers.
When configuring servers or development environments, it’s often necessary to look beyond official repositories. Packages in the stable release of a distribution may be out of date, especially where new or rapidly-changing software is concerned. Nevertheless, package management is a vital skill for system administrators and developers, and the wealth of packaged software for major distributions is a tremendous resource.
This guide is intended as a quick reference for the fundamentals of finding, installing, and upgrading packages on a variety of distributions, and should help you translate that knowledge between systems.
Most package systems are built around collections of package files. A package file is usually an archive which contains compiled applications and other resources used by the software, along with installation scripts. Packages also contain valuable metadata, including their dependencies, a list of other packages required to install and run them.
While their functionality and benefits are broadly similar, packaging formats and tools vary by platform:
.debpackages installed by
.rpmpackages installed by
.txzpackages installed by
In Debian and systems based on it, like Ubuntu, Linux Mint, and Raspbian, the package format is the
apt, the Advanced Packaging Tool, provides commands used for most common operations: Searching repositories, installing collections of packages and their dependencies, and managing upgrades.
apt commands operate as a front-end to the lower-level
dpkg utility, which handles the installation of individual
.deb files on the local system, and is sometimes invoked directly.
Recent releases of most Debian-derived distributions include a single
apt command, which offers a concise and unified interface to common operations that have traditionally been handled by the more-specific
Rocky Linux, Fedora, and other members of the Red Hat family use RPM files. These used to use a package manager called
yum. In recent versions of Fedora and its derivatives,
yum has been supplanted by
dnf, a modernized fork which retains most of
FreeBSD’s binary package system is administered with the
pkg command. FreeBSD also offers the Ports Collection, a local directory structure and tools which allow the user to fetch, compile, and install packages directly from source using Makefiles. It’s usually much more convenient to use
pkg, but occasionally a pre-compiled package is unavailable, or you may need to change compile-time options.
Most systems keep a local database of the packages available from remote repositories. It’s best to update this database before installing or upgrading packages. As a partial exception to this pattern,
dnf will check for updates before performing some operations, but you can ask at any time whether updates are available.
sudo apt update
sudo pkg update
sudo portsnap fetch update
Making sure that all of the installed software on a machine stays up to date would be an enormous undertaking without a package system. You would have to track upstream changes and security alerts for hundreds of different packages. While a package manager doesn’t solve every problem you’ll encounter when upgrading software, it does enable you to maintain most system components with a few commands.
On FreeBSD, upgrading installed ports can introduce breaking changes or require manual configuration steps. It’s best to read
/usr/ports/UPDATING before upgrading with
sudo apt upgrade
sudo dnf upgrade
sudo pkg upgrade
Most distributions offer a graphical or menu-driven front end to package collections. These can be a good way to browse by category and discover new software. Often, however, the quickest and most effective way to locate a package is to search with command-line tools.
apt search search_string
dnf search search_string
pkg search search_string
Note: On Rocky, Fedora, or RHEL, you can search package titles and descriptions together by using
dnf search all. On FreeBSD, you can search descriptions by using
pkg search -D
When deciding what to install, it’s often helpful to read detailed descriptions of packages. Along with human-readable text, these often include metadata like version numbers and a list of the package’s dependencies.
apt show package
dnf info package
pkg info package
cd /usr/ports/category/port && cat pkg-descr
Once you know the name of a package, you can usually install it and its dependencies with a single command. In general, you can supply multiple packages to install at once by listing them all.
sudo apt install package
sudo dnf install package
sudo pkg install package
Sometimes, even though software isn’t officially packaged for a given operating system, a developer or vendor will offer package files for download. You can usually retrieve these with your web browser, or via
curl on the command line. Once a package is on the target system, it can often be installed with a single command.
On Debian-derived systems,
dpkg handles individual package files. If a package has unmet dependencies,
gdebi can often be used to retrieve them from official repositories.
On On Rocky Linux, Fedora, or RHEL,
dnf is used to install individual files, and will also handle needed dependencies.
sudo dpkg -i package.deb
sudo dnf install package.rpm
sudo pkg add package.txz
Since a package manager knows what files are provided by a given package, it can usually remove them cleanly from a system if the software is no longer needed.
sudo apt remove package
sudo dnf erase package
sudo pkg delete package
In addition to web-based documentation, keep in mind that Unix manual pages (usually referred to as man pages) are available for most commands from the shell. To read a page, use
- man page
man, you can navigate with the arrow keys. Press / to search for text within the page, and q to quit.
This guide provides an overview of operations that can be cross-referenced between systems, but only scratches the surface of a complex topic. For greater detail on a given system, you can consult the following resources:
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up