How To Install Node.js using NVM | Install Node.js using NVM

Node.js is a JavaScript platform allows users to build network applications quickly. It leverages JavaScript on both the front and backend. Using Node.js development is more consistent and easy to integrate.

In this blog, I'll walk you through the installation process of node and npm.

Installing Using NVM

In my opinion, this is the best way to get node and npm installed in your system. You can follow the same process for windows, ubuntu or Linux system. The best approach to install is through a tool called nvm, which stands for "Node.js Version Manager". nvm works at the level of an independent directory within your home directory which means that we can install different versions of Node.js without affecting the entire system. This is useful when different projects in your system required a different version of Node.js.

You can find the nvm installation script from the project's GitHub page, you can use curl.

The version number highlighted here may differ

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash

The above script will install the software into a subdirectory of your home directory at ~/.nvm. It will install and add all the necessary lines of code to your ~/.profile file in order to use the file.

In order to gain access to the nvm functionality, you'll need to either quit and start the terminal or run source ~/.profile file so that your current session knows about the latest changes:

source ~/.profile

Once nvm is installed, you can now install different versions of Node.js. For different versions of Node.js which are available type:

nvm ls-remote
Output
...
 v14.9.0
 v14.10.0
 v14.10.1
 v14.11.0
 v14.12.0
 v14.13.0
 v14.13.1
 v14.14.0
 v14.15.0 (LTS: Fermium)
 v14.15.1 (Latest LTS: Fermium)
 v15.0.0
 v15.0.1
 v15.1.0
 v15.2.0
 v15.2.1
 v15.3.0

As from the list above the current LTS version at the time of this writing is v14.15.1. You can install the latest LTS version by typing:

nvm install 14.15.1

Usually, nvm will switch to use the most recently installed version. You can use the version you just downloaded by typing:

nvm use 14.15.1

Node is the executable which we get upon installation of Node.js using nvm. In order to see the version currently being used by the shell type:

node -v
Output
v14.15.1

Upon intalling node, npm is also installed along with node.

To check the current version of npm type:

npm -v
Output
6.14.5

In case of multiple Node.js versions installed, you can see what is installed by typing:

nvm ls
Output
 v12.18.1
-> v12.18.1

Removing Node.js

If you have decided to uninstall a version of Node.js that you have enabled using nvm, you'll first have to check if the version you'd like to remove is the currently active version. In order to determine the currently active version type:

nvm current

If the version you are targeting to remove is not the current active version, then, you can run:

nvm uninstall node_version

The above command will uninstall the specified version of Node.js.

In order to remove the currently active version of node you'll first have to deactivate nvm to enable your changes:

nvm deactivate

Now, finally, you can uninstall the current version using the uninstall command above mentioned, it will remove and clean all files associated with the targeted version of Node.js.

Conclusion

There are quite a number of ways to get up and running with Node.js on your system. But in my opinion nvm is the easiest method to get node up and running easily. Using nvm, it offers additional flexibility.

💌 If you'd like to receive more tutorials in your inbox, you can sign up for the newsletter here.

Discussions

Up next