如何在Ubuntu系统中安装旧版本Node.js?指定安装Node v=14.8.0与npm v=6.14.8的方法
Hey there! Let's walk through how to install Node.js v14.8.0 and its matching npm v6.14.8 on your Ubuntu system, replacing any newer versions you might have installed. This guide uses two common methods — pick the one that fits your workflow best.
Method 1: Use nvm (Recommended, for easy version management)
nvm (Node Version Manager) is the most hassle-free way to switch between Node.js versions without messing up your system setup.
Step 1: Uninstall existing Node.js/npm (if installed)
First, let's remove any current Node.js and npm installations to avoid conflicts:
- Uninstall the packages:
sudo apt remove --purge nodejs npm - Clean up leftover dependencies and configuration files:
sudo apt autoremovesudo rm -rf /usr/local/lib/node_modules /usr/local/bin/node /usr/local/bin/npm
Step 2: Install nvm dependencies
You'll need curl and git to set up nvm:sudo apt update && sudo apt install curl git -y
Step 3: Install nvm
Run the official nvm installation script (this sets up nvm in your user profile):curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
After running the script, restart your terminal or run this command to load nvm immediately:source ~/.bashrc
(If you use zsh instead of bash, replace .bashrc with .zshrc)
Step 4: Install Node.js v14.8.0
Use nvm to install the specific version:nvm install 14.8.0
This will automatically install the matching npm v6.14.8 along with Node.js.
Step 5: Set it as the default version
Make this the default Node.js version for all new terminal sessions:nvm alias default 14.8.0
Step 6: Verify the installation
Check that everything worked:node -v
You should see v14.8.0
npm -v
You should see 6.14.8
Method 2: Install binary package directly (No version manager)
If you don't want to use nvm, you can install the pre-built binary directly:
Step 1: Uninstall existing Node.js/npm (same as Method 1)
Follow Step 1 from Method 1 to remove any current installations.
Step 2: Download the Node.js 14.8.0 binary
Grab the 64-bit Linux binary package:curl -O https://nodejs.org/dist/v14.8.0/node-v14.8.0-linux-x64.tar.xz
Step 3: Extract the package to system directory
Extract the files to /usr/local (this will make node/npm available system-wide):sudo tar -xJf node-v14.8.0-linux-x64.tar.xz -C /usr/local --strip-components=1
Step 4: Verify the installation
Run the same check commands as before:node -v → v14.8.0npm -v → 6.14.8
If you run into any snags (like permission errors or version mismatches), feel free to ask for clarification — I'm here to help!
内容的提问来源于stack exchange,提问作者Milan jotva

