الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

dnf

Install, update, remove and search RPM packages from repositories, with all dependencies.

المستوى
امتحان RHCSA
المجموعة
حزم البرامج
يحتاج root
للتغييرات
الحزمة
dnf
يُسمّى أيضًا
yum

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

dnf is the package manager of RHEL (yum is a link to it). It reads the repositories in /etc/yum.repos.d/, solves dependencies, checks GPG signatures and keeps a history of every transaction that you can undo.

The general settings are in /etc/dnf/dnf.conf (like gpgcheck=1, installonly_limit=3 = keep 3 kernels). Commands that change the system need root; searching and listing do not.

طريقة الكتابة

dnf [OPTION]... COMMAND [ARGUMENT]...

الأجزاء الرئيسية

install PKG...
Install packages (names, files, URLs, @group).
remove PKG...
Remove packages and unneeded dependencies.
reinstall PKG...
Install the same version again.
upgrade [PKG...]
Update packages (all without names). update is the same.
upgrade-minimal
Only the updates needed for bug and security fixes.
downgrade PKG
Go back to an older version.
distro-sync
Make all packages match the repository versions.
check-update
List available updates (exit code 100 if there are some).
autoremove
Remove dependencies nothing needs anymore.
search WORD...
Search names and summaries (search all = also descriptions).
provides FILE
Find the package that gives a file or command.
info PKG
Details of a package.
list [installed|available|--upgrades]
List packages.
repolist [all|enabled|disabled]
List repositories.
repoinfo
Details of repositories.
repoquery
Advanced queries (dependencies, files, who requires).
deplist PKG
Dependencies of a package.
group list|info|install|remove
Package groups.
history [list|info|undo|redo|rollback]
Past transactions.
updateinfo
Advisories (security, bugfix).
mark install|remove PKG
Mark packages as user-installed or dependency.
swap OLD NEW
Replace one package by another in one step.
makecache
Download the repository indexes.
clean all|metadata|packages
Remove cached data.
config-manager
Add, enable or disable repositories (plugin).
needs-restarting
Show if a reboot or service restart is needed (plugin).
download PKG
Download the .rpm without installing (plugin).
shell
Interactive dnf shell.

الخيارات 50

الأكثر استخدامًا

Answers and output

-y, --assumeyes
Answer yes to all questions.
--assumeno
Answer no to all questions.
-q, --quiet
Less output.
-v, --verbose
More output.
--color=WHEN
always, never or auto.
-d, --debuglevel=LEVEL
Debug output level.
-e, --errorlevel=LEVEL
Error output level.

Repositories

--repo=REPOID
Use only this repository.
--enablerepo=REPOID
Enable a repository for this command.
--disablerepo=REPOID
Disable a repository for this command.
--repofrompath=REPO, PATH
Add a temporary repository.
-C, --cacheonly
Use only the cache; do not download indexes.
--refresh
Download fresh indexes first.
--releasever=VERSION
Use another release version.
--setopt=OPTION=VALUE
Set a config option for this command.
--nogpgcheck
Do not check signatures (not recommended).

Which packages

-x, --exclude=PKG
Leave these packages out.
--disableexcludes=all|main|REPOID
Ignore exclude settings.
--best
Use only the newest version, or fail.
--nobest
Allow older versions when the newest has problems.
--allowerasing
Allow removing packages to solve conflicts.
--skip-broken
Skip packages with dependency problems.
--showduplicates
Show all versions, not only the newest.
--obsoletes
Also handle obsoleted packages.
--noautoremove
Do not remove unneeded dependencies with remove.
--nodocs
Do not install documentation.
--forcearch=ARCH
Use another architecture.

Security updates

--security
Only security updates.
--bugfix
Only bug fix updates.
--enhancement
Only enhancement updates.
--newpackage
Only new package updates.
--advisory=ID
Only this advisory (RHSA-…).
--cve=CVE
Only updates for this CVE.
--bz=ID
Only updates for this Bugzilla ID.
--sec-severity=LEVEL
Only Critical, Important, Moderate or Low.

Downloads and others

--downloadonly
Download but do not install.
--downloaddir=DIR, --destdir=DIR
Where to put downloads.
--installroot=PATH
Install into another root folder.
-c, --config=FILE
Use another config file.
--comment=TEXT
Add a comment to the history.
--noplugins
Disable all plugins.
--disableplugin=NAMES
Disable some plugins.
--enableplugin=NAMES
Enable some plugins.
-R, --randomwait=MINUTES
Wait a random time first (for cron).
-4
Use IPv4 only.
-6
Use IPv6 only.
--rpmverbosity=NAME
rpm output level.
--debugsolver
Save debug data of the solver.
-h, --help
Show help.
--version
Show the version.

أمثلة 15

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Install a package

    dnf install -y httpd

    Dependencies come too.

  2. 2Find the package of a command

    dnf provides '*/semanage'
    policycoreutils-python-utils-3.8-1.el10.noarch : SELinux policy core python utilities

    Then install that package.

  3. 3Search for software

    dnf search nmap

    Searches names and summaries.

  4. 4Update everything

    dnf upgrade -y

    New kernels are added next to the old ones.

  5. 5Only security updates

    dnf upgrade --security -y
    dnf updateinfo list --security

    Patch fast with less risk.

  6. 6Install a local RPM file with dependencies

    dnf install -y ./tool-1.2-1.el10.x86_64.rpm

    Better than rpm -i: missing dependencies come from the repositories.

  7. 7Show repositories and enable one for a command

    dnf repolist all
    dnf install -y --enablerepo=codeready-builder-for-rhel-10-x86_64-rpms ninja-build

    The repo is used only for this command.

  8. 8Add a repository file

    dnf config-manager --add-repo http://repo.example.com/rhel10/AppStream

    Writes a .repo file in /etc/yum.repos.d/.

  9. 9Install a group

    dnf group install -y "Development Tools"

    Many packages for one job.

  10. 10Undo the last change

    dnf history
    dnf -y history undo last

    Removes what the last transaction installed.

  11. 11Show all versions and install an older one

    dnf list --showduplicates httpd
    dnf install -y httpd-2.4.62-1.el10

    Name-version-release selects the version.

  12. 12Keep a package on its version

    echo "excludepkgs=kernel*" >> /etc/dnf/dnf.conf

    Or use the versionlock plugin. Remove it later or you miss security fixes.

  13. 13Is a reboot needed after updates?

    dnf needs-restarting -r

    Kernel or glibc updates need a reboot.

  14. 14Download packages for an offline server

    dnf download --resolve --destdir=/tmp/pkgs nmap

    Copy the folder to the server and install with dnf install.

  15. 15Clean the cache after repository problems

    dnf clean all; dnf makecache

    Fixes errors from old indexes.

انتبه

  • The exam system has no Red Hat repositories: first create the .repo file.
  • --nogpgcheck and gpgcheck=0 trust any package. Only in labs.
  • dnf remove also removes dependencies; read the list before you say yes.

الملفات

/etc/dnf/dnf.conf
General settings.
/etc/yum.repos.d/*.repo
Repository definitions.
/var/cache/dnf/
Downloaded indexes and packages.
/var/log/dnf.log
Log of dnf actions.

رموز الخروج

0Done (check-update: no updates).
1Error.
100check-update: updates are available.
200Another dnf holds the lock.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man 8 dnf