Updating Packages in Rocky Linux Using DNF

Updating Rocky Linux is easy with DNF - unless sudo isn’t working. Here’s how to fix that and keep your system up to date.
Try the NVMe cloud.

Start your 7-day free trial with no commitment. Explore freely and continue if it’s right for you.

Updating packages in Rocky Linux is pretty straightforward, especially with DNF (Dandified YUM).

For our example, we will be logging into our system through a user account—in my case, vico—and trying to run DNF.

Fixing Sudo Access Issues

Not surprisingly, I am not part of the users allowed to use sudo.

We can work around this by using the command su (super user), which allows us to switch to the root account. To do this, we’ll be prompted for the root password.

Since we want to be able to run commands with our own account, we’ll use a very powerful command: visudo.

Before we run it, we need to specify the editor we want to use to edit the sudoers file. We can do this by running:

EDITOR=nano visudo

This ensures that we use nano instead of vi, saving us from the classic joke of having to turn off the computer to exit vi.

Next, we need to find the section in the file that mentions the root account. Navigate using the arrow keys or Page Up/Down until you see something like this:

Just below this, we will add our username following the same pattern. Use tabs instead of spaces to separate words in the same line.

Here’s what it should look like (replace vico with your actual username):

Save the changes by pressing CTRL+X, then Y, and hit Enter to exit.

Testing sudo Access

Exit from the root user and try running DNF with your user:

sudo dnf check-update

If everything is set up correctly, you should now have sudo privileges.

Updating Packages in Rocky Linux

Now it’s time to Dandify our experience. Let’s move to updating the packages on the system.

Checking for Available Updates

First, we check if there are any available updates:

sudo dnf check-update

If we have any pending packages to be installed, they will be shown in that screen.

Installing Updates

If everything is up to date, great! Otherwise, the system will install the necessary updates.

Cleaning Up Unnecessary Packages

For good housekeeping, let’s remove unnecessary packages and clear temporary files:

sudo dnf autoremove
sudo dnf clean all

Adding Extra Repositories to Rocky Linux

What if we need to install additional repositories? We can do that too!

For example, let’s install the EPEL (Extra Packages for Enterprise Linux) repository using DNF:

sudo dnf install epel-release -y

Once installed, we enable the repository:

sudo dnf config-manager --set-enabled epel

Then, we update the package list again to ensure everything is working:

sudo dnf update -y

Now that EPEL is installed, let’s do some final cleanup:

sudo dnf autoremove
sudo dnf clean all

Confirming Installed Repositories

To verify that the repository was added successfully, run:

sudo dnf repolist

If there were too many items on the list we can always run the same command – but using grep to find the specific item. For example:

sudo dnf repolist | grep epel

We get back the matches in the color red – a great way to give us better visibility when we really need it.

That’s it! Your Rocky Linux is now fully updated!

Picture of Vicente Muñoz

Vicente Muñoz

Vicente has a background in History, through formal education, and IT with 15 years of experience including 8 years focusing on cybersecurity. He has also worked as an author of books in the subjects of cybersecurity, programming, fantasy, and science fiction. Moreover, he managed and created an e-zine titled "El Futuro del Ayer, Hoy" (The Future of Yesterday, Today), with the core objective of giving new writers a voice.

Useful insights?

Help others discover this article by sharing it.