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. ]
저자 소개
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.
유사한 검색 결과
From maintenance to enablement: Making your platform a force-multiplier
Behind the scenes of RHEL 10, part 3
Where Coders Code | Command Line Heroes
What Kind of Coder Will You Become? | Command Line Heroes
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래