To install Node.js using NVM (Node Version Manager) on Linux, follow these steps:
Step 1: Install NVM
-
Open your terminal.
-
Run the following command to download and install NVM:
SHcurl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
🔹 Replace
v0.39.7
with the latest NVM version from the NVM GitHub. -
Reload your shell configuration to apply changes:
SHsource ~/.bashrc # For Bash users source ~/.zshrc # For Zsh users
-
Verify NVM installation:
SHnvm --version
If NVM is installed correctly, you’ll see its version number.
Step 2: Install Node.js Using NVM
-
List available Node.js versions:
SHnvm ls-remote
-
Install the latest stable Node.js version:
SHnvm install --lts
OR, install a specific version (e.g., 20.14.0):
SHnvm install 20.14.0
-
Verify the installation:
SHnode -v npm -v
Step 3: Set Default Node.js Version
If you have multiple Node.js versions, set a default version:
nvm use 20.14.0 # Use specific version
nvm alias default 20.14.0 # Set it as default
Step 4: Check Installed Node.js Versions
List all installed Node.js versions:
nvm ls
Step 5: Uninstall Node.js (If Needed)
To remove a specific Node.js version:
nvm uninstall 20.14.0
Bonus: Install Yarn (Optional)
If you need Yarn (a package manager alternative to npm), install it with:
npm install --global yarn
Verify with:
yarn -v