When hopping between Linux distributions, it can be challenging to smoothly transition between the different interfaces to package management tools. In this article, we're going to review some common operations and how to perform them using both dnf and apt.
Basic operations
Thankfully, most of your day-to-day basic operations can be performed in the same way using both tools. Installing a package by name is dnf install and apt install, and removing is dnf remove and apt remove. Removing dependencies that are no longer needed is dnf autoremove and apt autoremove.
Sometimes, you won't know the exact package name you need to get a certain tool. In those instances, you can use dnf search and apt search to search package names and descriptions. These tools support regular expressions, which can help trim down results.
root@ubuntu:~# apt search ripgrep
Sorting... Done
Full Text Search... Done
elpa-dumb-jump/groovy 0.5.3-1 all
jump to definition for multiple languages without configuration
ripgrep/groovy 12.1.1-1 amd64
Recursively searches directories for a regex pattern
ugrep/groovy 2.4.1+dfsg-1 amd64
faster grep with an interactive query UI
[root@fedora ~]# dnf search ripgrep
Last metadata expiration check: 0:04:09 ago on Sun 25 Oct 2020 09:43:35 PM UTC.
====================== Name Exactly Matched: ripgrep ======================
ripgrep.x86_64 : Line oriented search tool using Rust's regex library
[root@fedora ~]#
One "gotcha" to keep in mind is that the commands to upgrade operate slightly differently. dnf update and dnf upgrade both operate the same way and combine the steps performed by apt update and apt upgrade. This means that a dnf system will try and fetch any pending updates from its configured repositories and prompt the user to update packages, all in a single command. You still get the option to actually perform the update or not, of course, but it can be slightly surprising for folks used to Ubuntu to see a dnf update suddenly prompting the user to update packages. dnf distro-sync operates similarly, combining the functions of apt update and apt dist-upgrade.
[ Readers also liked: Create an Apache-based YUM/DNF repository on Red Hat Enterprise Linux 8 ]
Querying package information
When querying for package information, dnf offers a few small conveniences by combining some apt functionality into a single command. apt show will give you information about a package, and apt-cache policy will provide information about the repository a package came from and its upgrade status. dnf rolls all of this into dnf infoAnd also includes remote package information that apt provides via apt-cache show.
root@ubuntu:~# apt show curl
Package: curl
Version: 7.68.0-1ubuntu4
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Alessandro Ghedini <ghedo@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 411 kB
Depends: libc6 (>= 2.17), libcurl4 (= 7.68.0-1ubuntu4), zlib1g (>= 1:1.1.4)
Homepage: http://curl.haxx.se
Task: server, cloud-image, server-raspi, ubuntu-budgie-desktop
Download-Size: 161 kB
APT-Manual-Installed: no
APT-Sources: http://mirrors.digitalocean.com/ubuntu groovy/main amd64 Packages
Description: command line tool for transferring data with URL syntax
curl is a command line tool for transferring data with URL syntax, supporting
DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3,
POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP.
.
curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form
based upload, proxies, cookies, user+password authentication (Basic, Digest,
NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a
busload of other useful tricks.
root@ubuntu:~# apt-cache policy curl
curl:
Installed: 7.68.0-1ubuntu4
Candidate: 7.68.0-1ubuntu4
Version table:
*** 7.68.0-1ubuntu4 500
500 http://mirrors.digitalocean.com/ubuntu groovy/main amd64 Packages
100 /var/lib/dpkg/status
[root@fedora ~]# dnf info curl
Last metadata expiration check: 0:10:03 ago on Sun 25 Oct 2020 09:43:35 PM UTC.
Installed Packages
Name : curl
Version : 7.69.1
Release : 1.fc32
Architecture : x86_64
Size : 654 k
Source : curl-7.69.1-1.fc32.src.rpm
Repository : @System
From repo : anaconda
Summary : A utility for getting files from remote servers (FTP, HTTP, and others)
URL : https://curl.haxx.se/
License : MIT
Description : curl is a command line tool for transferring data with URL syntax, supporting
: FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, IMAP,
: SMTP, POP3 and RTSP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP
: uploading, HTTP form based upload, proxies, cookies, user+password
: authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer
: resume, proxy tunneling and a busload of other useful tricks.
Available Packages
Name : curl
Version : 7.69.1
Release : 6.fc32
Architecture : x86_64
Size : 289 k
Source : curl-7.69.1-6.fc32.src.rpm
Repository : updates
Summary : A utility for getting files from remote servers (FTP, HTTP, and others)
URL : https://curl.haxx.se/
License : MIT
Description : curl is a command line tool for transferring data with URL syntax, supporting
: FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, IMAP,
: SMTP, POP3 and RTSP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP
: uploading, HTTP form based upload, proxies, cookies, user+password
: authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer
: resume, proxy tunneling and a busload of other useful tricks.
To list files provided by a local package, you can use rpm -ql on dnf systems and dpkg -L on apt systems. To list the files provided by a remote package, however, it gets a bit more complicated. On dnf systems, this can be done via dnf repoquery -l. To do this on Ubuntu, you can use a utility called apt-file and run apt-file list. You might need to install this yourself, as it is maintained by the apt team but is not part of apt itself.
Downloading sources
Sometimes, you’ve just got to go digging through the source code to see what’s going on. Thankfully, there’s an easy way to get at the source code directly through your package manager. To display the source package to the given package name, use dnf repoquery -s and apt-cache showsrc. To grab it, dnf download --source will pull this down for you quickly, as will apt-get source.
In this article, we have run through a few common dnf and apt operations that systems engineers will encounter. For a more in-depth look at the options available on different distributions, I encourage you to take a look at the Pacman Rosetta available on the Arch Linux wiki. Though it is designed for users coming to Arch from other distributions, it is a great resource for anyone looking to translate from one distribution’s package manager to another for a huge range of common operations.
[ Free online course: Red Hat Enterprise Linux technical overview. ]
Sobre el autor
Jonathan Roemer is a senior DevOps engineer at Drizly with an interest in security, automation, and the human side of IT. He can usually be found hiking or reading a book on his porch.
Más como éste
More than meets the eye: Behind the scenes of Red Hat Enterprise Linux 10 (Part 4)
Looking ahead to 2026: Red Hat’s view across the hybrid cloud
The Infrastructure Effect | Command Line Heroes
The Ground Floor | Compiler: Tales From The Database
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Virtualización
El futuro de la virtualización empresarial para tus cargas de trabajo locales o en la nube