Ubuntu: how to fix error 404 Not Found for command apt install


Example error:

root@tutorialspots:~# apt install nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libevent-pthreads-2.1-7 libmecab2 libprotobuf-lite23 mecab-ipadic
  mecab-ipadic-utf8 mecab-utils
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libnode72 nodejs-doc
Suggested packages:
  npm
The following NEW packages will be installed:
  libnode72 nodejs nodejs-doc
0 upgraded, 3 newly installed, 0 to remove and 228 not upgraded.
Need to get 13.3 MB of archives.
After this operation, 51.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Ign:1 http://sg.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libnode72 amd64 12.22.9~dfsg-1ubuntu3.5
Ign:2 http://sg.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 nodejs-doc all 12.22.9~dfsg-1ubuntu3.5
Ign:3 http://sg.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 nodejs amd64 12.22.9~dfsg-1ubuntu3.5
Err:1 http://sg.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libnode72 amd64 12.22.9~dfsg-1ubuntu3.5
  404  Not Found [IP: 202.79.180.254 80]
Err:2 http://sg.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 nodejs-doc all 12.22.9~dfsg-1ubuntu3.5
  404  Not Found [IP: 202.79.180.254 80]
Err:3 http://sg.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 nodejs amd64 12.22.9~dfsg-1ubuntu3.5
  404  Not Found [IP: 202.79.180.254 80]
E: Failed to fetch http://sg.archive.ubuntu.com/ubuntu/pool/universe/n/nodejs/libnode72_12.22.9%7edfsg-1ubuntu3.5_amd64.deb  404  Not Found [IP: 202.79.180.254 80]
E: Failed to fetch http://sg.archive.ubuntu.com/ubuntu/pool/universe/n/nodejs/nodejs-doc_12.22.9%7edfsg-1ubuntu3.5_all.deb  404  Not Found [IP: 202.79.180.254 80]
E: Failed to fetch http://sg.archive.ubuntu.com/ubuntu/pool/universe/n/nodejs/nodejs_12.22.9%7edfsg-1ubuntu3.5_amd64.deb  404  Not Found [IP: 202.79.180.254 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Solution:
Step 1: restore the default repositories:

mkdir ~/backup
cd ~/backup/

cat << EOF > ~/backup/sources.list
deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner
EOF

sudo sed -i "s/focal/$(lsb_release -c -s)/" ~/backup/sources.list
sudo rm /etc/apt/sources.list
sudo cp ~/backup/sources.list /etc/apt/sources.list

Step 2: Move all the PPAs in your system to backup folder:

sudo mv /etc/apt/sources.list.d/* ~/backup

Step 3: Update the repositories:

sudo apt update

Leave a Reply