How to fix apt 404 Not Found error on Debian/Ubuntu

Last Updated:

You may encounter a “404 Not Found” error when you want to install a package in a Debian-based host. The reason is quite obvious, the URLs for downloading the packages are not working anymore, thus 404. For example, I was getting 404 error in a fresh installation of Debian 11 when I was trying to install openssh-server.

sudo apt install openssh-server

The error looks like the following:

Err:1 bullseye/main amd64 openssh-sftp-server amd64 1:8.4p1-5
  404  Not Found [IP: 80]
Err:2 bullseye/main amd64 openssh-server amd64 1:8.4p1-5
  404  Not Found [IP: 80]
E: Failed to fetch  404  Not Found [IP: 80]
E: Failed to fetch  404  Not Found [IP: 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
debian 11 returns 404 Not Found

How to Fix?

The Debian /etc/apt/sources.list file contains repository URLs for downloading any package. When the repository URLs are updated or redirected to other URLs, you will receive a 404 error. We need to update those URLs in our sources.list file.

Step 1: Find the outdated or broken repository URLs

From the output of your apt command, you will find the broken URLs.

Step 2: Find the updated repository URLs

For example, typing on the browser redirects to so we can update to in /etc/apt/sources.list. You can find a list of all Debian mirrors here.

Step 3: Backup your sources file

cp /etc/apt/sources.list /etc/apt/sources.list.bak

Step 4: Use sed to update the sources.list file

sed -i 's/' /etc/apt/sources.list

The -i option tell sed to directly make the changes in the file.

The s stands for substitute is the text we want to replace is the replacement or updated URL

g stands for global, meaning replace all occurrences

Step 5: Update the repository

sudo apt update

Step 6: Install the desired package

sudo apt intall openssh-server

This should be enough to fix the issue

fixed apt 404 not found on debian


Finding the corrupted URLs in the source repository files (/etc/apt/sources.list) and replacing them with the proper URLs which are working should be enough to solve this error.


This Post Has 2 Comments

  1. Hiveer

    It’s working, thanks for the sharing.

Leave a Reply