dnf

最後更新: 2020-07-10

DNF

dnf = Dandified Yum

 * All performance is good in terms of memory usage and dependency resolution of repository metadata.

 * It uses libsolv for dependency resolution

 * It is written in C, C++, Python

dnf vs yum

Yum Package Manager has been replaced by DNF Package Manager(successor to YUM )
(install or update the package, and its dependencies, using the rpm command)

目錄

 


Usage

 

Basic

dnf install packagename

dnf remove packagename

autoremove - removes packages installed as dependencies that are no longer required by currently installed programs.

List & Info

dnf list installed

dnf list available                   # Aliases: ls

dnf search packagename

dnf info packagename

Upgrade

check-update   # checks for updates, but does not download or install the packages.

upgrade          # checks the repositories for newer packages and updates them.

downgrade      # reverts to the previous version of a package.

Exclude

dnf upgrade --exclude=packagename

Exclude in config file

/etc/dnf/dnf.conf

excludepkgs=packagename

 


進階 Usage

 

provides

dnf provides YOUR_CLI

e.g.

dnf provides dig

Last metadata expiration check: 0:03:23 ago on Mon 18 Oct 2021 12:27:23 PM HKT.
bind-utils-32:9.11.26-4.el8_4.x86_64 : Utilities for querying DNS name servers
Repo        : appstream
Matched from:
Filename    : /usr/bin/dig

repolist

dnf repolist [--disabled|--all]

dnf repolist                                 # Lists all enabled repositories by default

repo id                                      repo name
appstream                                    Rocky Linux 8 - AppStream
baseos                                       Rocky Linux 8 - BaseOS
extras                                       Rocky Linux 8 - Extras

 


Plugin: Versionlock

 

# Install plugin

dnf install 'dnf-command(versionlock)'

# Usage

dnf versionlock add package

dnf versionlock delete package

i.e.

dnf versionlock add kernel zfs

# List all locked packages

dnf versionlock list

kernel-0:4.18.0-348.7.1.el8_5.*
zfs-0:2.0.7-1.el8.*

cat /etc/dnf/plugins/versionlock.list

kernel-0:4.18.0-348.7.1.el8_5.*
zfs-0:2.0.7-1.el8.*

# delete all locked entries

dnf versionlock clear

# Automatic Updates

The "dnf-automatic" package is a component that allows automatic download and installation of updates.

 


modular repository

 

 

A modular repository provides multiple module streams which contain additional RPM packages which can have the same name.

dnf  module [list|info|repoquery|install|remove|update|enable|disable|reset|provides|switch-to] ...

說明

  • list:                     Lists all(enable|disable) module  streams
  • enable|disable:    Enable a module stream
  • repoquery:          List all available packages belonging to selected modules
  • switch-to:            stronger version of the "dnf module enable" & "dnf module install" command
                              It does a distrosync to all modular packages in the enabled  & installed modules.

Example

[1] redis

dnf module list redis

dnf module switch-to redis:remi-6.2

[2] remi

dnf repolist    # Default enable  了 remi-modular 及 remi-safe

repo id                           repo name
...
remi-modular                      Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe                         Safe Remi's RPM repository for Enterprise Linux 8 - x86_64

dnf module list | grep php

php                  7.2 [d]         common [d], devel, minimal               PHP scripting language                                                                                         
php                  7.3             common [d], devel, minimal               PHP scripting language  
...
php                  remi-7.2        common [d], devel, minimal               PHP scripting language                                                                                         
php                  remi-7.3        common [d], devel, minimal               PHP scripting language  
...

dnf module switch-to php:remi-7.4

dnf module list | grep php

php                  7.2 [d]         common [d], devel, minimal               PHP scripting language
...
php                  remi-7.4 [e]    common [d], devel, minimal               PHP scripting language
...

dnf install php        # 由於行了 switch-to, 那會安 remi-7.4 的包

[3] RHEL 8 內的 php 8.2

dnf module switch-to php:8.2