A package manager works with repositories. It finds software, resolves dependencies, downloads packages and installs them. Debian and Ubuntu use APT. Fedora, Red Hat Enterprise Linux and relatives use DNF, the successor to YUM. On RHEL 9 and current Fedora, the yum command still works but runs DNF. Much older releases used the original yum program.
Commands that change the system need sudo.
Searching and inspecting
$ apt search htop
$ apt show htop
$ dnf search htop
$ dnf info htopInstalling
$ sudo apt install htop
The following additional packages will be installed:
libnl-3-200 libnl-genl-3-200
Do you want to continue? [Y/n]$ sudo dnf install htopBoth show what they plan to do. dnf asks before going ahead. apt also asks when extra packages are involved, as above. The -y option answers yes automatically. Read the plan before using it.
Updating
With APT there are two steps:
$ sudo apt update # refresh the package index
$ sudo apt upgrade # install newer versionsapt upgrade never removes installed packages. apt full-upgrade may remove some if that is needed to finish.
With DNF, one command does the usual job:
$ sudo dnf upgradeDNF refreshes its metadata when needed. On old yum systems the command is sudo yum update.
Removing
$ sudo apt remove htop
$ sudo apt purge htop # also delete system configuration files
$ sudo dnf remove htopCheck the list carefully. Removing one package can take others that depend on it. Neither remove nor purge is meant to clean up files in your home directory.
To drop dependencies that are no longer needed, use sudo apt autoremove or sudo dnf autoremove.
apt and apt-get
apt is designed for people at a terminal. In scripts, use apt-get, whose behaviour and output are meant to stay stable. Other families have their own managers, such as zypper on openSUSE and pacman on Arch Linux.
Try it
These commands only read information, so they are safe to run:
$ apt show bash
$ apt list --installed
$ dnf info bash
$ dnf list --installedUse the pair that matches your system. Then install a small package, run it and remove it again, ideally on a test machine such as the one in the packages, disk and FHS lab.
Check your understanding
yum and apt
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.