Fix dnf that will not install

We'll check connectivity, repo config, disk space, and locks—then fix repo URLs, GPG keys, or metadata—or tell you when to escalate.

Category
Troubleshooting · Servers & Linux
Time
10–25 min
Last reviewed
What you'll need
  • SSH or console access with sudo

Step-by-step diagnostic

Step 1 of 11
Show full guide

Steps

Goal: Check connectivity, repo config, disk space, and locks—then fix repo URLs, GPG keys, or metadata.

  • Run sudo dnf install <package>. Note the exact error.
  • Good: You see a specific error (connection, 404, GPG, disk full, lock). Proceed to Check connectivity.
  • Bad: dnf hangs—check connectivity and timeouts.

Check error and connectivity

Goal: Confirm the error and test repo reachability.

  • Run dnf repolist and inspect /etc/yum.repos.d/*.repo for baseurl or metalink.
  • Test with curl -I <baseurl> or ping the host. If unreachable, the repo URL or mirror is wrong.
  • Run df -h and confirm / and /var have free space. dnf needs space in /var/cache/dnf.
  • Good: Repo is reachable and disk has space. Proceed to Fix repo config if needed, or Clear metadata.
  • Bad: Repo unreachable or disk full—fix the repo URL or free space first.

Fix repo config

Goal: Fix baseurl or metalink so dnf can reach the repo.

  • Edit the .repo file in /etc/yum.repos.d/. Set baseurl to a known-good mirror (e.g. vault.rockylinux.org for old Rocky). Check that enabled=1.
  • Run sudo dnf clean all and sudo dnf makecache. Retry sudo dnf install <package>.
  • If the error is GPG-related, import the key with sudo rpm --import <key-url> or temporarily set gpgcheck=0 to test—do not leave disabled in production.
  • Good: Metadata loads and packages install. Bad: Same error—check connectivity again or escalate.

Clear metadata

Goal: Remove corrupted metadata and retry.

  • Run sudo dnf clean all to clear cached metadata. Then sudo dnf makecache and sudo dnf install <package>.
  • Good: Install succeeds. Bad: Escalate with the error and repo config.

When to escalate

Escalate if:

  • The repo is managed by a central team and you cannot change it.
  • The mirror is enterprise-internal and unreachable from your network.
  • The fix requires network or firewall changes outside your control.

Provide: the dnf error, dnf repolist output, and contents of /etc/yum.repos.d/*.repo.

Verification

  • sudo dnf install <package> completes without errors.
  • The package is installed and rpm -q <package> shows the version.
  • No GPG or connection errors in the output.

Escalation ladder

Work from the device outward. Stop when the problem is fixed.

  1. Capture error Run dnf install; note exact error.
  2. Connectivity and disk Test repo URL with curl; check df -h.
  3. Repo config Edit baseurl/metalink; dnf clean all; makecache.
  4. GPG keys Import correct key or temporarily disable gpgcheck to test.
  5. Escalate Enterprise-managed repo or infrastructure change needed.

What to capture if you need help

Before calling support or posting for help, have these ready. It speeds everything up.

  • Exact dnf error message
  • Output of dnf repolist
  • Contents of /etc/yum.repos.d/*.repo
  • df -h and disk usage

Does dnf install show a specific error?

Run sudo dnf install <package> and note the error: connection, 404, GPG, disk full, or lock.

Run `sudo dnf install <package>`. Good: You see a specific error (connection refused, 404, GPG, disk full, lock). Bad: dnf hangs with no output—check connectivity and timeouts.

You can change your answer later.

Check connectivity and timeouts

Test repo URL with `curl -I <baseurl>` or `ping` the host. If unreachable, fix network or use a different mirror. Check `df -h` for full disk.

Can you reach the repo URL?

Test with curl -I or ping. Repo must return HTTP 200 or be reachable.

Run `dnf repolist` and check baseurl/metalink in `/etc/yum.repos.d/`. Test with `curl -I <url>`. Good: HTTP 200 or host reachable. Bad: Timeout or 404—fix repo URL or mirror.

You can change your answer later.

Fix repo URL and retry

Edit the .repo file in `/etc/yum.repos.d/`. Set baseurl to a known-good mirror (e.g. vault.rockylinux.org for old Rocky). Run `dnf clean all` and `dnf makecache`. Retry `dnf install`.

Is disk space sufficient?

dnf needs space in /var and /var/cache/dnf.

Run `df -h`. Check `/` and `/var`. Good: At least a few percent free. Bad: Near 100%—free space or expand volume. See fix-linux-runs-out-of-disk for disk full.

You can change your answer later.

Is another dnf process holding the lock?

Only one dnf process can run at a time.

Run `ps aux | grep -E "dnf|yum"` and check for pid files. Good: No other process or stale lock. Bad: Another admin is running installs—wait, or kill only if you are sure it is stale.

You can change your answer later.

Wait or remove stale lock

If another admin is installing, wait. If the lock is stale (no process), remove the pid file and retry.

Is the error GPG-related?

GPG key retrieval failed or GPG check failed.

Import the correct key: `sudo rpm --import https://mirror.example.com/RPM-GPG-KEY`. Or temporarily set gpgcheck=0 in the repo to test—do not leave disabled in production. Good: Install succeeds. Bad: Other error—check metadata with `dnf clean all` and `dnf makecache`.

You can change your answer later.

Import GPG key and retry

Get the correct key from the repo or distro docs. Run `sudo rpm --import <key-url>`. Retry `dnf install`.

Clear metadata and retry

Run `sudo dnf clean all`, then `sudo dnf makecache` and `sudo dnf install <package>`. Corrupted metadata can cause odd failures.

Escalate

Escalate if the repo is enterprise-managed, you cannot change infrastructure, or disk cannot be expanded. Provide dnf error, repolist output, and repo config.

Reviewed by Blackbox Atlas

Frequently asked questions

Why would dnf install fail?
Network or repo URL unreachable, expired or wrong GPG key, full disk, another dnf/yum process holding the lock, or corrupted metadata. Check the error message first.
Can I fix dnf install myself?
Yes. Check connectivity, repo config, disk space, and locks. Fix baseurl or metalink, import GPG keys, clear metadata with dnf clean all, or remove stale lock files.
When should I escalate dnf install failures?
If the repo is enterprise-managed and you cannot change it, or the fix requires infrastructure changes outside your control.

Rate this guide

Was this helpful?

Thanks for your feedback.

Continue to