How to install Node.js on Ubuntu via NVM
Share this:
NVM (Node Version Manager) is a powerful tool that allows you to quickly install, manage, and switch between different versions of Node.js from the command line.
Step 1: Install NVM Dependencies
To get started with NVM, run one of the following commands based on your preferred method for downloading files:
- Using curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
- Using wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
These commands download and execute the installation script for NVM.
The script will clone the NVM repository into the ~/.nvm directory and attempt to add the necessary source lines to your profile file, such as ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc, depending on your shell.
Step 2: Verify NVM Installation
To confirm that NVM has been successfully installed, run the following command to check its version:
nvm --version
If the command outputs the version number, you’re all set up!
Step 3: Install Node.js with NVM
With NVM installed, you can easily install the latest version of Node.js by running:
nvm install node
To check the installed version of Node.js, use the following command:
node --version
If you need to install a specific version of Node.js, simply specify the version number:
nvm install 22.11.0
Some Useful NVM Commands
Here are some handy NVM commands to manage your Node.js versions:
- List all Node.js versions installed
nvm ls - Switch Node.js Version
nvm use v20.18.0 - List the available Node.js versions
nvm ls-remote - Install Current LTS Version
nvm install --lts - Uninstall a Node.js Version
nvm uninstall 22.11.0 - Install Stable Node.js Version
nvm install stable - Set the default Node.js version
nvm alias default 22.11.0