Fix Ubuntu & Mint apt-get 404 Not Found Package Repository Errors
The Advanced Packaging Tool (as in apt-get) is a great way to install packages, but if you have an older install then like me, you know how utterly frustrating it can be when this system stops working with 404 Not Found errors.
The situation is easily fixable but it's worth taking a few moments to understand how the system works. APT relies on repositories in order to find software and resolve dependencies. Repositories are simply directories on a server, containing packages along with an index file.
Standard Ubuntu releases are supported for only 9 months, whereas 'LTS' (Long Term Support) releases are supported for 5 years. Once support expires for your version of Ubuntu (and its derivatives, such as Mint) the repository gets shifted elsewhere. This means installs will no longer be available at the original location: http://archive.ubuntu.com/ubuntu/dists/ - hence the error messages when running apt-get install and apt-get update.
On the local machine /etc/apt/ has the apt configuration folders and files. This includes the following..
/etc/apt/sources.list - Locations to fetch packages from
/etc/apt/sources.list.d/ - Directory containing additional source list fragments
/etc/apt/apt.conf - APT configuration file
/etc/apt/apt.conf.d/ - Directory containing APT configuration file fragments
/etc/apt/preferences - version preferences file. (modify to get certain packages from a separate source or different version of a distribution)
/var/cache/apt/archives/ - storage area for retrieved package files.
One option is to do a version upgrade, although this isn't always what's required..
sudo apt-get dist-upgrade
To fix the error, the trick is to replace the entries in the local /etc/apt/sources.list to reflect the new server locations for the older files. Specifically all entries for "archive.ubuntu.com" and "security.ubuntu.com" need to be changed to "old-releases.ubuntu.com". Either edit the file manually or if you're feeling lazy, running the following command should achieve this..
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
For Mint also run this command to modify the official-package-repositories.list..
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list.d/official-package-repositories.list
Check if there are other files in /etc/apt/sources.list.d/ which need to be updated..
grep -E 'archive.ubuntu.com|security.ubuntu.com' /etc/apt/sources.list.d/*
If so, edit the entries manually. Finally update the sources list..
sudo apt-get updateBack