Ubuntu使用n工具安装Node.js时目录缺失问题求助
n Version Manager Hey there, let's tackle this frustrating Node.js version issue you're facing. You tried upgrading from the ancient Node.js 4.2.6 (installed via apt) to 10.17.0 using the n tool, but ran into missing directory errors—and even though the system claimed success, your node version still shows the old one. Here's what's going on and how to fix it:
What's Causing the Problem?
The cp errors you're seeing mean the n tool couldn't find the expected directories (lib, bin, etc.) for Node.js 10.17.0. This almost always happens because:
- The Node.js 10.17.0 package didn't download completely (likely due to proxy/network issues during the install)
- The incomplete package was partially extracted, leaving missing folders
- Your system's
node/nodejscommands are still pointing to the apt-installed version instead of the onentried to set up
Step-by-Step Fixes
1. Clean Up the Broken Node.js 10.17.0 Installation
First, let's get rid of the incomplete files that are causing errors:
# Try removing the broken version via n first sudo n rm 10.17.0 # If that throws an error (since the directories are missing), delete the folder manually sudo rm -rf /usr/local/n/versions/node/10.17.0
2. Configure Your Proxy for npm and n
Since you mentioned a proxy bypass requirement, make sure npm is configured to use your proxy so the Node.js package downloads properly this time:
# Replace with your actual proxy details npm config set proxy http://your-proxy-host:your-proxy-port npm config set https-proxy http://your-proxy-host:your-proxy-port # If your proxy requires authentication, use this format instead: # npm config set proxy http://username:password@your-proxy-host:your-proxy-port # npm config set https-proxy http://username:password@your-proxy-host:your-proxy-port
3. Reinstall the n Tool (to ensure it's up-to-date)
Outdated versions of n can have bugs with older Node.js releases like 10.17.0. Refresh it first:
sudo npm cache clean -f sudo npm install -g n@latest
4. Install Node.js 10.17.0 with Verbose Logging
This time, run the install with verbose mode so you can see if the download completes successfully:
sudo n -v 10.17.0
Look for lines indicating the package was downloaded and extracted fully—if you see errors here, double-check your proxy settings.
5. Fix the node/nodejs Command Path
Even if installation succeeds, your system might still be using the old apt-installed Node.js. Let's fix that:
# Check where your current node/nodejs commands point to which node which nodejs # If they point to /usr/bin/nodejs (the apt version), create a symlink to the n-installed version sudo rm /usr/bin/node sudo ln -s /usr/local/n/versions/node/10.17.0/bin/node /usr/bin/node sudo ln -s /usr/local/n/versions/node/10.17.0/bin/npm /usr/bin/npm
6. Verify the Fix
Finally, check if everything worked:
node -v # Should show v10.17.0 npm -v # Should show 6.11.3
内容的提问来源于stack exchange,提问作者Mark Ryan

