Node.js download page: https://nodejs.org/en/download/package-manager
Method 1: Manual Installation via Archive
After downloading the appropriate package from the link above, extract it to /env/nodejs (adjust the path as needed).
- Create symbolic links
sudo ln -s /env/nodejs/node-v16.18.0-linux-x64/bin/npm /usr/local/bin/
sudo ln -s /env/nodejs/node-v16.18.0-linux-x64/bin/node /usr/local/bin/
- Set mirror registry
npm config set registry https://registry.npmmirror.com/
- Verify registry
npm config get registry
- Install cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com/
- Create symlink for cnpm
sudo ln -s /env/nodejs/node-v16.18.0-linux-x64/bin/cnpm /usr/local/bin/
Method 2: Using nvm
# Install nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Download and install Node.js (you may need to restart the terminal)
nvm install 20
# Verify versions
node -v # should output `v20.15.1`
npm -v # should output `10.7.0`
Useful comamnds:
nvm list— List installed versionsnvm list installed— List installed versionsnvm list available— List available versionsnvm version— Show current nvm versionnvm install— Install latest versionnvm use <version>— Switch to a specific versionnvm ls— List all versionsnvm current— Show current active versionnvm alias <name> <version>— Set an aliasnvm unalias <name>— Remove an aliasnvm reinstall-packages <version>— Reinstall global packages for a versionnvm on— Enable Node.js version managementnvm off— Disable Node.js version managementnvm proxy— View or set proxynvm node_mirror <url>— Set or view Node.js mirrornvm npm_mirror <url>— Set or view npm mirrrornvm uninstall <version>— Uninstall a versionnvm use [version] [arch]— Use a version with optional architecturenvm root [path]— Set or view root path
Method 3: Using fnm
# Install fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash
# Download and install Node.js
fnm use --install-if-missing 20
# Verify versions
node -v # should output `v20.15.1`
npm -v # should output `10.7.0`
Useful commands:
fnm install <version>— Install a specific versionfnm install --lts— Install LTS versionfnm uninstall <version>— Uninstall a versionfnm uninstall <alias>— Uninstall an aliased versionfnm use <version|alias>— Use a specific versionfnm alias <name> <version>— Set a aliasfnm unalias <name>— Remove an aliasfnm default <version>— Set the default version