安装npm时出现404 Not Found错误,含libssl-dev获取失败该如何解决?
Hey there, let's work through those 404 errors you're facing while installing npm. Both issues trace back to problems with Ubuntu's package repositories, so here's a step-by-step breakdown to fix them:
This usually pops up when your system's package index is outdated or the repository server can't serve the requested packages. Try these steps:
- First, run
sudo apt update --fix-missing— this command will repair any broken index files and refresh your repository information. - If the error persists, chances are your Ubuntu version is no longer supported (like 16.04 or earlier), and the official security repositories have moved to old-releases. Here's how to switch:
- Back up your current sources list first:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak - Edit the sources file with a text editor:
sudo nano /etc/apt/sources.list - Replace every instance of
security.ubuntu.com/ubuntuandarchive.ubuntu.com/ubuntuwithold-releases.ubuntu.com/ubuntu - Save and exit (press Ctrl+O, hit Enter, then Ctrl+X), then run
sudo apt updateagain.
- Back up your current sources list first:
If you're getting a specific 404 for the libssl-dev_1.0.2d-0ubuntu1.5_amd64.deb package, it means this exact version is no longer hosted on the standard security repo. Try this:
- Download the package directly from the old-releases archive:
wget http://old-releases.ubuntu.com/ubuntu/pool/main/o/openssl/libssl-dev_1.0.2d-0ubuntu1.5_amd64.deb - Install the downloaded package:
sudo dpkg -i libssl-dev_1.0.2d-0ubuntu1.5_amd64.deb - If you hit dependency errors during installation, run
sudo apt -f installto automatically fix missing dependencies.
If you keep running into issues with Ubuntu's package manager, using NVM (Node Version Manager) is a great workaround. It lets you install Node.js and npm independently of your system's packages:
- Clone the NVM repository to your home directory:
git clone https://github.com/nvm-sh/nvm.git ~/.nvm - Add the NVM initialization lines to your shell config file (like
.bashrcor.zshrc):export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" - Reload your shell (or run
source ~/.bashrc), then install the latest Node.js (which includes npm):nvm install node
内容的提问来源于stack exchange,提问作者Ayush

