Linux Package Management
What Is Package Management?
A package manager is a tool used to install, update, and remove software on a Linux system. It downloads software from configured repositories and handles many of the tasks required to install and maintain it.
For example, instead of downloading Git manually, you can install it using a single command. The package manager also resolves required dependencies and keeps track of installed packages.
Different Linux distributions use different package managers:

dnf is the modern successor to yum in many RPM-based distributions. The available command depends on the Linux distribution and version.
Updating the Package Index
Before installing software on Ubuntu or Debian, refresh the local list of available packages:
sudo apt updateThis command downloads updated package information from the configured repositories. It helps apt identify which package versions are available.
Important: apt update refreshes package information; it does not upgrade the software already installed on your system.
To upgrade installed packages, use:
sudo apt upgradeReview the proposed changes before confirming an upgrade, especially on production servers.
Installing Software
The general syntax for installing a package with apt is:
sudo apt install package-nameLet's look at some common examples.
Installing Git
Git is a version control system used to track changes in source code.
sudo apt install gitVerify the installation:
git --versionIf Git is installed successfully, the command displays its version.
Installing Maven
Maven is a build automation and dependency management tool commonly used in Java projects.
sudo apt install mavenThe package manager installs Maven along with the dependencies required by the package. Whether a Java runtime is installed as part of this operation depends on the package dependencies and the system's existing software.
Verify the installation:
mvn --versionCheck Java separately:
java -versionIf Java is not installed, you may need to install a suitable Java package for your project.
Installing Nginx
Nginx is a web server commonly used to serve static files and act as a reverse proxy.
sudo apt install nginxAfter installation, you can check whether the service is running:
systemctl status nginxOn systems using systemd, you can start the service with:
sudo systemctl start nginxInstalling a package does not guarantee that its service has started automatically. The behavior depends on the package and system configuration.
Removing Software
To uninstall a package while generally retaining its system-wide configuration files, use:
sudo apt remove nginxTo remove the package along with its package-managed configuration files, use:
sudo apt purge nginxNote: Neither command necessarily removes every file associated with the application. Files created manually or stored outside the package's managed locations may remain.
After removing packages, you can check whether unused dependencies can be removed:
sudo apt autoremoveReview the list before confirming, particularly on servers where other software may depend on installed packages.
Common Package Management Commands
| Command | Purpose |
|---|---|
sudo apt update | Refresh available package information |
sudo apt upgrade | Upgrade installed packages |
sudo apt install git | Install Git |
sudo apt remove nginx | Remove a package while generally retaining configuration |
sudo apt purge nginx | Remove a package and its package-managed configuration |
sudo apt autoremove | Remove packages no longer needed as dependencies |
apt list --installed | List installed packages |
apt show git | Display package details |
git --version | Check the installed Git version |
Package Management on Amazon Linux and RHEL-Based Systems
Ubuntu and Debian use apt, while Amazon Linux and RHEL-based distributions use RPM package management tools such as dnf or yum.
Common examples include:
# Install a package
sudo dnf install git
# Remove a package
sudo dnf remove git
# Refresh package information
sudo dnf check-updateOn systems that use yum, the equivalent installation and removal commands are:
sudo yum install git
sudo yum remove gitThe exact commands and behavior can vary by distribution and version. Check which package manager is available on your system before using these examples.
Summary
- A package manager simplifies software installation, upgrades, and removal.
- Use
apton Ubuntu/Debian anddnforyumon supported RPM-based distributions. - Run
sudo apt updateto refresh package information; usesudo apt upgradeto upgrade installed packages. - Package managers resolve dependencies automatically, reducing the need for manual installation.
- Use
apt removeto uninstall a package,apt purgeto remove its package-managed configuration, andapt autoremoveto clean up unneeded dependencies. - Verify installations with the software's own version command, such as
git --versionormvn --version.
Written By: Muskan Garg
How is this guide?
Last updated on
