Skip to content
Linux

Package Management

Install, update, and search packages on Debian and RHEL.

By EZ4Code Team
packageaptdnf

Code

# Debian/Ubuntu (APT)
sudo apt update
sudo apt install -y nginx
sudo apt upgrade
sudo apt remove --purge nginx
apt search redis
apt show nginx

# RHEL/Fedora (DNF/YUM)
sudo dnf install -y nginx
sudo dnf update
sudo dnf remove nginx
dnf search redis

# Find which package provides a file
dpkg -S /usr/bin/curl           # Debian
rpm -qf /usr/bin/curl           # RHEL

# List installed files
dpkg -L nginx
rpm -ql nginx

# Hold a package from upgrades
sudo apt-mark hold nginx
sudo apt-mark unhold nginx

Explanation

APT (Debian/Ubuntu) and DNF (RHEL/Fedora) install, update, and remove packages from repositories. apt update refreshes indexes before apt upgrade applies updates. dpkg -S and rpm -qf identify which package owns a file, while apt-mark hold pins a version to prevent unintended upgrades.

More Linux Snippets