Node.js
Source: [REF-1] Install Node.js Locally with Node Version Manager (nvm)
Install - FRESH nodejs using fnm, or nvm
fnm (Fast Node Manager) is the latest and recommended package manager now.
Updated: 2024 Jul
source: https://nodejs.org/en/download/package-manager/
# installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash
# download and install Node.js
fnm use --install-if-missing 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`The following scripts clone the nvm repository then update the profile .bash_profile.
# check [REF-3] Github for the latest version
$ curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# the script install "export NVM_DIR=..." to .bashrc because
# .bash_profile does not exist
$ source ~/.bashrc
# when using the interactive terminal
#source ~/.bash_profile
# verify installation
$ command -v nvm
# install latest LTS node.js
$ nvm install --lts
# checked installed version - Jun 23, 2022
$ node --version
v16.15.1
$ npm --version
8.11.0
You can confirm that the profile is updated by looking at the install script's output to determine which file it used. Look for something like the following in that file:
$ export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completionDownload the Windows Binary (.zip) from https://nodejs.org/en/download/
Extract the zip file and copy the
nodejsfolder toC:\<app-folder>Setup Environment Variable; add
C:\<app-folder>\nodejsOpen the Windows "System Properties", edit the "Path" for the "user variables for <username>", to set the environment variable
Verify installation
C:\>node --version
v18.12.0
C:\>npm --version
8.19.2
C:\>npx --version
8.19.2
C:\>Downloading the zip file, unzip it to an <app_folder> of your choice, then set the `PATH` so that windows can find it. NOTE: I think this is the BEST approach. ⭐⭐⭐
See https://nodejs.org/en/download/prebuilt-binaries
To UPGRADE, just download another zip, unzip it and set the PATH to the new folder.
[Alternative] Install - nodejs using apt
Update nodejs version in WSL
Source: Install Node.js on Windows Subsystem for Linux (WSL2)
Tested (Jul 2024) on the following existing setup:
nvm,nodejshave been installed but older version then need to update; Current LTS version: v20.15.1;Inspect existing environments:
wsl:~$ node --version
v18.16.0
wsl:~$ npm --version
9.5.1
wsl:~$ nvm --version
0.39.3
wsl:~$ nvm ls
-> v18.16.0
default -> lts/* (-> v18.16.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.16.0) (default)
stable -> 18.16 (-> v18.16.0) (default)
lts/* -> lts/hydrogen (-> v18.16.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.0 (-> N/A)
lts/hydrogen -> v18.16.0Update nodejs
# find the available versions
nvm ls-remote
nvm install 20.15.1
nvm install 20.15.1 --reinstall-packages-from=18.16.0
# upgrade npm if necessary
npm install -g npm@10.8.1
# uninstall old version
nvm uninstall 18.16.0References
[REF-2] npm-doc Downloading and installing Node.js and npm
[REF3] Github Node Version Manager
[REF-4] DigitalOcean How To Install Node.js on Ubuntu 20.04
Last updated