How to fix package sources in old Ubuntu releases

When using an old Ubuntu release, apt update throws errors and notices due to expired sources URLs…

When using an old Ubuntu release, the package URLs stored in /etc/apt/sources.list no longer point to valid addresses. Eventually this causes apt update to throw errors and notices.

To fix this, the sources URLs in sources.list should be updated. Here is a command to do that:

# backup your the file we will change
cp /etc/apt/sources.list /etc/apt/sources.list.bak

# update the URLs with the "archive" ones
sed -i -re 's/([a-z]{2}.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

# run update again to check
apt update

# if everything checks out ok, remove the backup file
rm -f /etc/apt/sources.list.bak

A Thank You to Dean Lewis, the author of the source: https://veeamvanguards.com/ubuntu-apt-get-update-fails-the-repository-no-longer-has-a-release-file/