Node.js is a popular, open-source server-side platform that runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.). It uses JavaScript on the server and is widely used for building efficient, scalable network applications.
Node Version Manager (NVM), on the other hand, is a tool that allows developers to install and manage multiple Node.js versions. It’s incredibly useful for testing applications across different Node versions, ensuring compatibility and stability.
This tutorial will help you to install and manage Node.js using NVM on Linxu systems.
Pre-Installation Requirements
Before diving into the installation process, ensure that your system meets the following requirements:
- A compatible operating system (Linux, macOS, or Windows).
- Basic knowledge of terminal or command line interface.
- Internet connection for downloading necessary files.
Step 1 – Install NVM
NVM is a command-line utility to install and manage Node.js versions for specific users. You can install nvm using a shell script provided by the nvm team.
- First, make sure you have curl installed on your system:
sudo apt update && sudo apt install curl -y
- Next, run the following command to configure nvm on your system for the current logged user.
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
- Reload the system environment using this command. It will set the required environment variables to use nvm on the system.
source ~/.bashrc
Step 2 – Find Available Node.js Version
At this point, you have installed nvm on your system for the current user. Now find out the available version of Node.js to install. Use ls-remote
option to list versions.
nvm ls-remote
You will see a long list of available versions.
Output:... ... v20.8.0 v20.8.1 v20.9.0 (LTS: Iron) -> v20.10.0 (Latest LTS: Iron) v21.0.0 v21.1.0 v21.2.0 v21.3.0 v21.4.0 v21.5.0
Step 3 – Installing Node.js with NVM
To set up the specific version of Node.js you need for your application, use the following command to install Node.js version 20.10.0, which is the Long Term Support (LTS) release:
nvm install v20.10.0
Alternatively, if you prefer to install the latest version simply type ‘node’ instead of any version. For example:
nvm install node
To install multiple versions of Node.js on your system, simply repeat the relevant command with the desired version number.
Step 4 – Change Default Node Version
As you have installed multiple node.js versions, You can select the specific version of node.js as the default version used by the system and load it into the environment. Use the below command to list the currently installed version and the default set version.
nvm list
Output:v20.10.0 -> v21.5.0 default -> 20 (-> v20.10.0) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v21.5.0) (default) stable -> 21.5 (-> v21.5.0) (default) lts/* -> lts/iron (-> v20.10.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.2 (-> N/A) lts/hydrogen -> v18.19.0 (-> N/A) lts/iron -> v20.10.0
You can see that Node.js version v21.5.0
is set as the default version. You can change the default Node.js version. The below command will set 20.10.0
as the default Node.js version.
nvm use 20.10.0
Now verify the current active version of node.js
node --version
v20.10.0
Step 5 – Run Application with Specific Version
If you have multiple node.js applications on your system and want to run each with a specific version of node.js. NVM provides you an option to use a node.js version for running any application. For example
nvm run v20.10.0 app.js
Step 6 – Remove Unused Node.js Version
This command will provide a list of installed versions of node.js on your system.
nvm list
You can remove any unused version from your system. For example, to remove Node.js version 12 execute the following command:
nvm uninstall 12
Conclusion
NVM is an essential tool for Node.js developers, offering flexibility and control over various Node.js versions. With NVM, you can seamlessly switch between projects requiring different Node versions, ensuring compatibility and efficient development.
For more detailed information and advanced features, visit the official NVM GitHub page. Remember, the key to mastering NVM is practice and exploration, so don’t hesitate to experiment with its features!
23 Comments
Muchas gracias, excelente documento. Claro, preciso y conciso. Saludos desde Perú.
Clear and concise. Thank you for the gift of time saved!
Works great.. thank you.
Thanks Bro!
No Non-Sense Explanation, Very useful.
Thankyou.
This works great!
perfect.
Nice very informative and updated,,,million thanks
Thanks, the guide is very concise and useful.
Thx!
thanks
Wow, it works,
ça marche correctement. Merci
Many thanks 😀
thanks alot man!
Thank you very much. This just what I needed to install the latest version of Nodejs on MX Linux. Other methods responded with an error message stating that it could not be installed on ‘Continuum’.
System Info: ‘Desktop: Xfce 4.12.3 Distro: MX-18.3_x64 Continuum Feb 9 2019’
i found out that nvm is easier to use compared to npm. thanks!
`nvm remove v10.15.0` is not a valid command. Use `nvm uninstall v10.15.0`
Thanks R,
Thank you
Thanks for ur information
Thanks for detailing them!
Life saver, thanks
Thanks for your help…