apt and dnf do the same job on different Linux families: apt manages .deb packages on Debian, Ubuntu and Mint, and dnf manages .rpm packages on Fedora, RHEL, Rocky and AlmaLinux. Most commands map one to one (apt install is dnf install), but apt needs apt update to refresh package lists before installing, while dnf refreshes its metadata automatically.
apt vs dnf command cheat sheet
Run these with sudo when they change the system.
| Task | apt (Debian, Ubuntu) | dnf (Fedora, RHEL) |
|---|---|---|
| Refresh package lists | apt update | dnf makecache (usually automatic) |
| List available upgrades | apt list --upgradable | dnf check-upgrade |
| Upgrade all packages | apt upgrade | dnf upgrade |
| Install a package | apt install nginx | dnf install nginx |
| Install a local file | apt install ./app.deb | dnf install ./app.rpm |
| Remove a package | apt remove nginx | dnf remove nginx |
| Remove including config files | apt purge nginx | no direct equivalent |
| Remove unused dependencies | apt autoremove | dnf autoremove |
| Search | apt search nginx | dnf search nginx |
| Show package details | apt show nginx | dnf info nginx |
| List installed packages | apt list --installed | dnf list --installed |
| Which package provides a file | dpkg -S /usr/bin/curl | dnf provides /usr/bin/curl |
| Transaction history and undo | logs in /var/log/apt/history.log, no undo command | dnf history list, dnf history undo last |
Difference 1: refreshing package lists
apt keeps a local copy of what each repository offers and only updates it when you ask. The apt manual describes update as downloading package information from all configured sources, and upgrade as installing available upgrades for installed packages. Two separate steps, so the usual sequence is:
sudo apt update
sudo apt upgrade
Skipping apt update is a common cause of E: Unable to locate package on a fresh system, and of installing outdated versions.
dnf checks repository metadata itself. Its metadata_expire setting defaults to 48 hours: after that, the next command re-downloads the metadata before doing anything. So sudo dnf upgrade on its own is the normal way to update a Fedora system. dnf makecache exists if you want to refresh in advance, and dnf check-upgrade only lists what would change.
Difference 2: what happens to dependencies on remove
When you remove a package with dnf, it also removes dependencies that were pulled in only for that package and aren't needed any more. That is the clean_requirements_on_remove setting, which defaults to true. Packages you installed by name are never removed this way.
apt's remove leaves those dependencies installed and tells you so. A simulated removal on Ubuntu 22.04 (apt -s remove curl) prints:
The following package was automatically installed and is no longer required:
libcurl4
Use 'apt autoremove' to remove it.
The following packages will be REMOVED:
curl ubuntu-wsl
You clear those leftovers with sudo apt autoremove. Note the second line of the removal list: removing one package can also remove packages that depend on it, so read the list before confirming.
apt also distinguishes remove, which, per its manual, leaves small modified configuration files behind, from purge, which deletes them too. dnf has no separate purge command.
Difference 3: undoing a change
dnf records each transaction and can reverse it. The history command offers list, undo (revert one transaction) and rollback (undo everything after a given transaction):
sudo dnf history list
sudo dnf history undo last
apt keeps a readable log at /var/log/apt/history.log showing what each run installed, upgraded and removed, but there is no built-in undo. You reverse a change by removing or reinstalling the listed packages yourself.
Difference 4: scripting
apt is designed for people at a terminal. Its manual says the command line "is designed as an end-user tool and it may change behavior between versions", and recommends apt-get and apt-cache in scripts. apt even warns you when its output goes to a pipe. Real output from Ubuntu 22.04:
$ apt list --installed | head -2
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
In a script or Dockerfile, use apt-get update && apt-get install -y nginx. dnf has no separate scripting tool; use dnf -y install nginx to answer yes automatically.
dnf, dnf5 and yum
Fedora 41 switched the default package manager from dnf (version 4) to DNF5, a rewrite. The dnf command now runs dnf5, and the dnf5 package also provides a yum symlink for compatibility. The old dnf-3 binary stays available. Day-to-day commands are the same, and old yum install instructions still work. Check which version you have with dnf --version.
Which one do you use?
Whichever your distribution ships; you don't choose them independently. To find out, run cat /etc/os-release and look at the ID and ID_LIKE lines: ubuntu or debian means apt; fedora, rhel or a RHEL rebuild such as Rocky or AlmaLinux means dnf. If you are on Windows with WSL, the default distribution is Ubuntu, so it is apt; see how to install WSL.
One related trap for Python users: if pip install fails with externally-managed-environment on Debian or Ubuntu, install the distribution's package (sudo apt install python3-requests) or use a virtual environment; see the fix for that error. For the commands you'll run around package management, see basic Linux commands.
Frequently asked questions
- Is dnf better than apt?
- Neither is better in general. Both resolve dependencies, verify package signatures and handle upgrades well. The real choice is the distribution: apt comes with Debian and Ubuntu and installs .deb packages, dnf comes with Fedora and the RHEL family and installs .rpm packages. You use whichever your distribution ships.
- Can I use apt on Fedora or dnf on Ubuntu?
- Not in any useful way. Each manager works with its own package format and its distribution's repositories, so the packages, names and dependencies would not match. Install software on Fedora with dnf and on Ubuntu with apt.
- What is the difference between apt and apt-get?
- apt is the newer, friendlier front end for interactive use, with progress bars and combined commands. apt-get and apt-cache are the older tools with a stable interface. The apt manual recommends apt-get and apt-cache in scripts, and apt prints a warning that it has no stable CLI interface when its output is piped.
- What is the difference between dnf and yum?
- dnf replaced yum on Fedora and RHEL-family systems and accepts mostly the same commands. On current Fedora the yum command is kept as a symlink for compatibility, so yum install still works but runs dnf.