Can make DNF cache system wide instead of per user?

From time to time, I will forgot and keep doing below:

As normal user:
dnf search xyz
(update repo data, takes a while, then return result.)
dnf install XYZ
(need root access)
sudo dnf install XYZ
(need to update repo data for root user one more time.)

4 Likes
sudo tee /etc/profile.d/custom.sh << "EOF"
dnf() {
sudo dnf "${@}"
}
EOF
. /etc/profile
5 Likes

Thank you very much!

2 Likes

This was my problem too and I would like to show my solution i came up with. I was thinking how to run always DNF as sudo.
My workaround was the following:

Creating a small script where i can store under $HOME/bin and where also are all my self-made scripts.
($HOME/bin is per default in the search path, it just has to be created if not available)
I named the script dnf

#!/bin/bash
if [ "$1" = "" ]; then
   sudo dnf
else
   sudo dnf $1 $2 $3 $4
fi

Now the script just has to be executable. In the settings of the terminal the option " run command as login shell" has also to be active.

I like @vgaetera version better. Just both ways achieved the same result.

@vgaetera i guess i could use the "${@}" instead of $1 $2 $3 $4 for the arguments ?
Btw thx for sharing such snippets !

2 Likes

alias dnf='sudo dnf' in your bashrc for single user or in the profile.d for all users. And I also have some lines in the sudoers configuration so I don’t need to type the password for each dnf call. This might be too much for the default install but is there some place for configuration bits like this where new users can find, learn and understand those?

2 Likes

We can use tags to mark posts good for new users.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.