Debian and Ubuntu are popular Linux distributions for home users. These distributions and their derivatives use the Advanced Package Tool (APT). Other distributions use alternative package managers, like DNF, YUM, Pacman, which have unique functionalities and syntax.
Be cautious with package managers as they install software and dependencies and may affect your system's configuration.
Run installation, removal, and repository changes as root or with sudo. Read-only searches and queries usually need no elevation. Package and service names differ by distribution: Apache is commonly apache2 on Debian/Ubuntu and httpd on Fedora/RHEL.
User
|
| uses
V
Package Manager (e.g., APT, DNF, YUM, Pacman)
|
| fetches metadata and package lists from
V
Package Repository
|
| downloads
V
Package files (.deb, .rpm, .tar.xz, etc.)
|
| unpacks/installs to
V
System directories (/usr/bin, /usr/lib, etc.)
APT (Advanced Package Tool) is the package-management system used by Debian-based distributions. The apt command provides an interactive interface; apt-get and apt-cache remain appropriate for scripts because their interfaces emphasize compatibility. aptitude is a separate frontend, not simply a superseded version of apt.
I. Updating Repository Information
Before installing or upgrading packages, update the list of available packages and their versions:
apt updateII. Upgrading Installed Packages
To upgrade all installed packages to their latest available versions:
apt upgradeIII. Installing New Packages
To install a new package from the repositories, such as Apache on Debian/Ubuntu:
apt install apache2IV. Installing Local .deb Files
If you have a .deb package file downloaded locally, install it using:
apt install /path/to/package/name.debV. Verifying Installation
To inspect repository metadata for the package:
apt show apache2apt show can describe a package that is not installed. Check local installation status separately with dpkg-query -W -f='${Status}\n' apache2; an installed package reports install ok installed.
YUM (Yellowdog Updater, Modified) is associated with older Red Hat-based distributions. Current Fedora/RHEL-family systems commonly use DNF, and yum may be a compatibility command. YUM/DNF refresh expired repository metadata automatically; this differs from the usual explicit apt update step, but does not mean they operate without a metadata cache.
For DNF, the corresponding common commands are dnf check-update, dnf upgrade, dnf install httpd, and dnf remove httpd. A check-update exit status of 100 means updates are available, not that the query failed. The YUM examples below remain useful for older systems.
I. Checking for Updates
To check available updates for installed packages:
yum check-updateII. Updating All Packages
To update all packages to their latest versions:
yum updateIII. Updating Specific Packages
To update a particular package, such as httpd:
yum update httpdIV. Searching for Packages
To search for a package by name. For example, searching for apache:
yum search apacheV. Installing Packages
To install a specific package, like httpd:
yum install httpdVI. Displaying Package Information
To display detailed information about a package:
yum info httpdVII. Listing Installed Packages
To display a list of all installed packages:
yum list installedVIII. Removing Packages
To remove an installed package, such as httpd:
yum remove httpdIX. Cleaning Cache
To clean the YUM cache, which includes removing downloaded packages and metadata:
yum clean allInstalling software from tarballs is an alternative to using package managers on Linux. This manual method is broken down into three primary steps:
I. Extract
First, navigate to the directory containing the tarball. Use the following command to extract its contents:
tar -zxvf path_to_tar.tar.gz
cd path_to_tar
II. Compile
The process might vary depending on the software, but generally, you would run:
make
If there is a configuration file (configure script) present, especially one listing dependencies, run it before executing make.
III. Install
Installation is often done through make install, which should place the executable in the correct directory:
make install
Alternatively, for some software, you may need to manually copy the compiled executable to a directory like /usr/local/bin.
🔴 Caution: Remember that software installed via tarballs does not benefit from automatic updates typically provided by package managers. This means manually tracking and updating software for security patches and new features.
RPM (Red Hat Package Manager) is a low-level package manager used in Red Hat-based Linux distributions. It allows direct management of software packages but requires a bit more manual intervention compared to higher-level tools like YUM.
I. Downloading RPM Packages
To download an RPM package from a website:
wget http://some_website/sample_file.rpmII. Installing Packages with RPM
To install a downloaded RPM package:
rpm -ivh sample_file.rpmi stands for install, v for verbose (showing detailed output), and h for hash (displaying progress as hash marks).
III. Listing All Installed Packages
To list all installed packages:
rpm -qaIV. Listing a Specific Package
To check if a specific package, like nano, is installed:
rpm -q nanoV. Displaying Package Documentation
To display documentation files of a specific package:
rpm -qd nanoVI. Removing Packages with RPM
To remove an installed package:
rpm -e nanoe stands for erase, which removes the package.
🔴 Note: While RPM provides a granular control over package management, it doesn't resolve dependencies automatically. It's important to ensure that dependencies are managed manually or through a higher-level tool like YUM or DNF.
A software package repository in the context of Linux and other Unix-like operating systems is a centralized storage location containing various software packages. These repositories are essential components in the package management system, utilized by package managers to download and install software and updates.
The CentOS 7 URLs below illustrate historical repository syntax. CentOS Linux 7 is end of life; use your supported distribution's current repository configuration rather than copying these endpoints. Repository labels and package contents vary by vendor and release.
- The label might be something like
base,updates, orextras, which uniquely identifies each repository in configuration files. For example, in a YUM repository configuration, the label[base]identifies the base repository. - The name could be descriptive, such as "CentOS Base Repository" or "Fedora Updates", giving a clear indication of the content or purpose. For instance, "CentOS Base" suggests this repository contains the core CentOS packages.
- A mirrorlist example could look like
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os. This URL directs the system to a list of available mirrors that host the repository, ensuring a fast and reliable download experience. - The base URL might be specified as
http://mirror.centos.org/centos/7/os/x86_64/, indicating the primary location where the RPM packages for CentOS 7 are stored. Users download packages directly from this URL if the mirrorlist is not used. - The GPG Check setting in a repository configuration might look like
gpgcheck=1, where the value1indicates that GPG signature verification is enabled. This ensures that the packages are authentic and have not been tampered with.
- The Base repository, for instance, could include packages like
glibc,bash, andkernel, which are essential components of the operating system. These packages are crucial for the system's basic operation and are well-tested. - The Updates repository may provide updated versions of core packages, such as
httpd(Apache HTTP Server) oropenssl, containing security fixes and performance improvements. For example, a critical security patch foropensslwould appear in the Updates repository. - An Optional repository might include packages like
nginx,mysql-community-server, or other open-source software that, while useful, is not officially supported by the distribution's core team. These packages provide additional capabilities but may have less thorough testing. - The Supplemental repository could offer proprietary software such as
Oracle Javaor commercial fonts. These are not open-source and are often provided with restrictions on usage, but they expand the range of software available on the system. - The Extras repository might contain newer or experimental software, such as a beta version of
gccorPython, which is not yet included in the Base repository. This repository allows users to access the latest features and test them before they become part of the standard offering.
APT repositories are defined in /etc/apt/sources.list and in the /etc/apt/sources.list.d/ directory.
- The
add-apt-repositorycommand is used to add or remove APT repositories. - It modifies the
/etc/apt/sources.listfile or creates new files in/etc/apt/sources.list.d/. - Install this utility with the following commands:
apt update
apt install software-properties-commonTo demonstrate managing APT repositories, here's how you can install Wine on a Debian-based system:
This example targets the historical Ubuntu 20.04 (focal) repository, not arbitrary Debian/Ubuntu releases. Before using it, follow WineHQ's current distribution-specific instructions, including supported release, architecture, and key verification. A repository signing key should be scoped to that repository with signed-by, rather than trusted globally.
I. Get and Install the Repository Key
Download and install the GPG key for the Wine repository:
wget -nc https://dl.winehq.org/wine-builds/winehq.key
sudo install -d -m 0755 /etc/apt/keyrings
sudo gpg -o /etc/apt/keyrings/winehq.gpg --dearmor winehq.keyII. Add the Wine Repository
Add the Wine repository to your system's sources:
sudo add-apt-repository 'deb [signed-by=/etc/apt/keyrings/winehq.gpg] https://dl.winehq.org/wine-builds/ubuntu/ focal main'III. Update the Package Database
Update APT's package database to recognize the new repository:
apt updateIV. Install Wine
Install the stable version of Wine with:
sudo apt install --install-recommends winehq-stableV. Verify the Installation
Confirm that Wine is correctly installed:
wine --version🔴 Note: It's important to ensure that repositories and their keys are obtained from trusted sources to avoid security risks. Incorrect or malicious repositories can compromise the system's integrity and security.
The configuration files for YUM repositories are located in the /etc/yum.repos.d directory.
I. Display Repositories
To display a list of all enabled and available repositories, use:
yum repolist allII. Add a New Repository
To add a new repository by specifying its URL, use the yum-config-manager tool:
yum-config-manager --add-repo=[URL]III. Enable a Repository
If a repository is disabled and you want to enable it, use the following command. Replace [repo_id] with the actual repository ID:
yum-config-manager --enable [repo_id]IV. Disable a Repository
To disable a repository (for example, to prevent updates from that repository), use the command below. The change is saved as enabled=0 and persists until you re-enable it; for a single command, use --disablerepo=[repo_id] instead:
yum-config-manager --disable [repo_id]- Configure a Linux system to use both official and third-party repositories while preventing package conflicts.
- Safely upgrade a major software package (like Python or MySQL) ensuring all system dependencies are maintained.
- Script a solution to automatically switch to a backup repository when the primary YUM or APT repository fails.
- Create a script or use existing tools to automate security updates on a Linux system without breaking package dependencies.
- Download and compile a piece of software from a tarball, resolving all dependencies manually.
- Use the
alientool or similar to convert an RPM package to a DEB package and ensure it installs correctly on a Debian-based system. - Is it possible for apt to remove an already installed package when you install a new one? If so, under what circumstances can this occur?
- Set up and configure a custom YUM repository on a CentOS system.
- Install a Linux software package on a system without direct internet access using offline methods.
- Write a script to automate the cleanup of old or unused packages and maintenance tasks like cache clearing in a Linux environment.