Basic Package Management

Install a Package

sudo dnf install <package_name>

Installs the specified package.


Remove a Package

sudo dnf remove <package_name>

Removes the specified package.


Update a Specific Package

sudo dnf update <package_name>

Updates the specified package to the latest version.


Update All Packages

sudo dnf update

Updates all installed packages to their latest versions.


List All Installed Packages

dnf list installed

Displays a list of all installed packages.


Show Package Information

dnf info <package_name>

Displays detailed information about the specified package.


Search for Packages by Name

dnf search <package_name>

Searches for packages by their names.


Search for Packages by Description

dnf search <keyword>

Searches for packages by keywords in their descriptions.


Download a Package Without Installing

dnf download <package_name>

Downloads the specified package without installing it.


Repository Management

Add a Repository

  1. Create a .repo file in /etc/yum.repos.d/:
    sudo nano /etc/yum.repos.d/<repo_name>.repo
    
  2. Add repository details to the file.

Disable a Repository

sudo dnf config-manager --set-disabled <repo_name>

Disables the specified repository.


Enable a Repository

sudo dnf config-manager --set-enabled <repo_name>

Enables the specified repository.


List All Repositories

dnf repolist

Displays a list of all configured repositories.


Cleaning Up

Remove Unused Packages

sudo dnf autoremove

Removes packages that were installed as dependencies but are no longer needed.


Clean Cache

sudo dnf clean all

Cleans all cached files.


Clean Metadata Cache

sudo dnf clean metadata

Cleans the metadata cache.


Clean Packages Cache

sudo dnf clean packages

Cleans the packages cache.


Clean Expired Cache

sudo dnf clean expire-cache

Cleans the expired cache.


Group Management

List Available Groups

dnf group list

Lists all available package groups.


Install a Group

sudo dnf group install "<group_name>"

Installs all packages in the specified group.


Remove a Group

sudo dnf group remove "<group_name>"

Removes all packages in the specified group.


History and Rollback

View Transaction History

dnf history

Displays the transaction history.


View Details of a Specific Transaction

dnf history info <transaction_id>

Displays details of the specified transaction.


Undo a Specific Transaction

sudo dnf history undo <transaction_id>

Undoes the specified transaction.


Redo a Specific Transaction

sudo dnf history redo <transaction_id>

Redoes the specified transaction.


Additional Commands

Check for Available Updates

dnf check-update

Checks for available updates.


List Enabled Repositories

dnf repolist enabled

Lists all enabled repositories.


List Disabled Repositories

dnf repolist disabled

Lists all disabled repositories.


Upgrade System to a New Release

sudo dnf system-upgrade download --releasever=<version>
sudo dnf system-upgrade reboot

Upgrades the system to a new release.


Synchronize Installed Packages to Latest Available Versions

sudo dnf distro-sync

Synchronizes installed packages to the latest available versions.


Display DNF Version

dnf --version

Displays the current version of DNF.


Get Help on DNF Commands

dnf help

Displays help information for DNF commands.


Removing Old Kernels

List Installed Kernels

dnf list installed kernel

Lists all installed kernels.


Check Current Running Kernel

uname -r

Displays the current running kernel version.


Automatically Remove Old Kernels

  1. Configure DNF to keep only the latest two kernels:
    sudo nano /etc/dnf/dnf.conf
    
    Add or modify the following line:
    installonly_limit=2
    
  2. Apply cleanup to remove old kernels:
    sudo dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
    

Manually Remove Specific Old Kernels

  1. List all installed kernels:
    dnf list installed kernel
    
  2. Identify the old kernel versions you want to remove. Do not remove the currently running kernel (you can check it with uname -r).
  3. Remove a specific old kernel:
    sudo dnf remove kernel-<version>
    

Using package-cleanup for Managing Kernels

  1. Install dnf-utils:
    sudo dnf install dnf-utils
    
  2. Keep only the latest 2 kernels:
    sudo package-cleanup --oldkernels --count=2
    

Keep this cheat sheet handy for efficient and effective system management using DNF!

Last updated 01 Sep 2024, 10:22 CEST . history