Azure Ubuntu 16.04执行apt-get install npm时404报错,求解决方案
Absolutely, adjusting your apt sources is a solid fix here—let’s walk through exactly what to do, plus cover some key context and extra checks to get you up and running smoothly.
为什么会出现这个404错误?
Ubuntu 16.04 LTS (Xenial Xerus) reached end-of-life in 2021, meaning official support (and package hosting) for it has stopped. Azure’s dedicated repo azure.archive.ubuntu.com has likely removed 16.04’s package indexes entirely, which is why your apt-get install npm is failing.
1. 切换到old-releases.ubuntu.com(推荐方案)
The standard archive.ubuntu.com no longer hosts 16.04 packages either, so the most reliable fix is to switch to Ubuntu’s official old releases archive. Here’s how:
- First, back up your original sources list to avoid accidental breakage:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak - Replace all instances of
azure.archive.ubuntu.comwithold-releases.ubuntu.comusing a one-line sed command:
Or if you prefer editing manually (with nano):sudo sed -i 's/azure.archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
Update every line containingsudo nano /etc/apt/sources.listazure.archive.ubuntu.comto useold-releases.ubuntu.com, then save and exit (Ctrl+O, press Enter, Ctrl+X). - Refresh your package index to pull from the new source:
sudo apt-get update - Now install npm without the 404 error:
sudo apt-get install npm -y
2. What about using archive.ubuntu.com?
You could try replacing azure.archive.ubuntu.com with archive.ubuntu.com, but this is not recommended. Most of 16.04’s packages have been migrated to old-releases.ubuntu.com, so you’ll still likely hit 404s here. Stick with the old releases repo for consistent access.
3. Extra troubleshooting steps
- If you still see errors after updating
sources.list, check for third-party repo files in/etc/apt/sources.list.d/—these might also reference the old Azure or standard archive URLs, and you’ll need to update those toold-releases.ubuntu.comtoo. - The version of npm in 16.04’s repo is quite outdated. After installing, consider upgrading to a newer stable version:
Note: Very old npm/node versions may have compatibility issues with modern packages. If your application needs newer features, look into usingsudo npm install -g npm@latestnvm(Node Version Manager) to install a supported Node version.
4. Long-term recommendation
Ubuntu 16.04 no longer receives security updates, which poses significant risks for your server. If possible, plan to upgrade to a supported LTS version (like 20.04 or 22.04 LTS) either via Azure’s in-place upgrade tools or by deploying a new instance. This is the most secure and sustainable solution.
内容的提问来源于stack exchange,提问作者Alex Lee

