You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Ubuntu 16.04执行apt-get install npm时404报错,求解决方案

解决Azure上Ubuntu 16.04 LTS安装npm时的apt-get 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.com with old-releases.ubuntu.com using a one-line sed command:
    sudo sed -i 's/azure.archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
    
    Or if you prefer editing manually (with nano):
    sudo nano /etc/apt/sources.list
    
    Update every line containing azure.archive.ubuntu.com to use old-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 to old-releases.ubuntu.com too.
  • The version of npm in 16.04’s repo is quite outdated. After installing, consider upgrading to a newer stable version:
    sudo npm install -g npm@latest
    
    Note: Very old npm/node versions may have compatibility issues with modern packages. If your application needs newer features, look into using nvm (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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:07:12