Installing Software with Package Managers
In Linux, managing software through package managers is an essential skill, as it allows you to install, update, and remove applications efficiently. Package managers streamline software management by automating the retrieval, installation, and dependency handling of software packages. Different Linux distributions use different package managers, with apt commonly used for Ubuntu and Debian systems, and yum or dnf for CentOS and RHEL (Red Hat Enterprise Linux). Let’s dive into how these package managers work, their key commands, and examples of their usage.
1. Ubuntu/Debian Package Management with apt
aptThe apt (Advanced Package Tool) package manager is used to manage software on Debian-based distributions like Ubuntu. It’s user-friendly, powerful, and handles dependencies automatically, ensuring all required packages are installed for a software to run.
Updating Package Lists:
sudo apt update: This command updates the local list of available packages and their versions, which ensures that the latest versions are fetched when you install or upgrade software.$ sudo apt updateThis command doesn’t upgrade any software—it simply refreshes the package index, showing what’s available in the repositories.
Installing Software:
sudo apt install packagename: Installs a specific package from the repositories. For example:$ sudo apt install curlThis command installs
curland any dependencies required for it to run. If the package is already installed,aptwill display a message confirming it.
Upgrading Installed Software:
sudo apt upgrade: Upgrades all installed packages to their latest available versions based on the updated package list.$ sudo apt upgradeTo upgrade individual packages, use
sudo apt install --only-upgrade packagename.
Removing Software:
sudo apt remove packagename: Removes an installed package without deleting its configuration files.$ sudo apt remove curlsudo apt purge packagename: Removes a package and its configuration files, leaving no traces.$ sudo apt purge curl
Cleaning Up Unused Packages:
sudo apt autoremove: Removes packages that were installed as dependencies but are no longer required.$ sudo apt autoremove
Example Workflow: Suppose you want to install a new software package, ensure it’s up to date, and remove unused dependencies:
sudo apt updatesudo apt install packagenamesudo apt upgradesudo apt autoremove
This series of commands ensures a clean and updated system.
2. CentOS/RHEL Package Management with yum or dnf
yum or dnfOn CentOS, RHEL, and Fedora, the package managers used are yum (Yellowdog Updater, Modified) and dnf (Dandified YUM). dnf is the modern replacement for yum and is used by default in recent versions of Fedora, CentOS 8+, and RHEL 8+. Both yum and dnf are similar in functionality to apt but have their syntax and commands specific to the RPM package format used on these systems.
Basic Commands with yum
Installing Software:
sudo yum install packagename: Installs a package, along with any required dependencies.
Updating Package Lists:
Unlike
apt,yumdoesn’t require a separate update of package lists. Instead,yumrefreshes lists each time an install or update command is run. However, you can still check for updates:
Upgrading Packages:
sudo yum update: Updates all installed packages on the system.You can also update a single package:
Removing Software:
sudo yum remove packagename: Uninstalls a package and removes any dependencies that are no longer needed.
Basic Commands with dnf
dnf is similar to yum but is designed to be faster and more efficient with better dependency handling.
Installing Software:
sudo dnf install packagename: Installs a package along with its dependencies.
Updating Software:
sudo dnf upgrade: Upgrades all installed packages to the latest versions, similar toyum update.
Removing Software:
sudo dnf remove packagename: Uninstalls a package, removing its dependencies if they’re no longer required.
Clearing Cache:
sudo dnf clean all: Clears cached data, which helps free up disk space and ensures fresh package lists.
Example Workflow: To install, update, and manage packages on a CentOS/RHEL system:
sudo yum install packagenameorsudo dnf install packagenamesudo yum updateorsudo dnf upgradesudo yum autoremoveorsudo dnf autoremove
Using dnf instead of yum generally results in faster operations and better dependency resolution.
3. Advanced Package Management Commands
In both apt and dnf/yum, there are additional commands for more advanced package management:
List Installed Packages:
apt list --installed(Debian/Ubuntu) oryum list installed/dnf list installed(CentOS/RHEL): Lists all installed packages, allowing you to verify if specific software is present on the system.
Searching for Packages:
apt search keyword: Searches for available packages containing a specific keyword.yum search keywordordnf search keyword: Searches for available packages in the repository.
Checking Package Info:
apt show packagenameoryum info packagename/dnf info packagename: Shows detailed information about a package, including its version, description, and dependencies.
Viewing Logs:
cat /var/log/apt/history.log(Debian/Ubuntu) orcat /var/log/yum.log(CentOS/RHEL): Views recent package management activity, useful for auditing and troubleshooting.
Key Differences Between apt, yum, and dnf
apt, yum, and dnfPackage Format:
aptworks with.debpackages, whileyumanddnfwork with.rpmpackages.Cache Management:
dnfautomatically manages and cleans its cache better thanyumorapt, reducing unnecessary disk usage.Dependency Handling:
dnfhas enhanced dependency resolution compared toyum, making it faster and more efficient for updates and installations.
Summary of Package Management Commands
Ubuntu/Debian:
sudo apt update– Updates package lists.sudo apt install packagename– Installs a package.sudo apt upgrade– Upgrades all packages.sudo apt remove packagename– Removes a package.
CentOS/RHEL:
sudo yum install packagenameorsudo dnf install packagename– Installs a package.sudo yum updateorsudo dnf upgrade– Upgrades all packages.sudo yum remove packagenameorsudo dnf remove packagename– Removes a package.
Last updated
