For enquiries call:

Phone

+1-469-442-0620

April flash sale-mobile

HomeBlogWeb DevelopmentInstalling and Managing Node.JS Using Node Version Manager (Nvm)

Installing and Managing Node.JS Using Node Version Manager (Nvm)

Published
18th Sep, 2023
Views
view count loader
Read it in
10 Mins
In this article
    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Node.js is the backbone of any modern project. It is not just another Backend technology, but also comes in-built with a package manager called npm. The npm package manager is required in all projects which need external node packages like ReactJS or Angular or Vue.

    Node.js is the second most popular backend technology after Java and is preferred by both start-ups and enterprises to build MERN(MongoDB, ExpressJS, ReactJS, NodeJS), MEAN(MongoDB, ExpressJS, Angular, NodeJS) or MEVN(MongoDB, ExpressJS, VueJS, NodeJS) stack projects. Companies like Netflix, NASA, Trello, PayPal, Uber, Yahoo use them for their large-scale projects. NodeJS is a completely open-source project, as the code is freely available on GitHub. It has a continually active development community. As it is been used in all top tech companies, so it is backed by funding and support from most of them.

    NodeJS has two ongoing releases, LTS and current, and, therefore two different versions. We will learn about them next.

    Understanding Node.js releases

    If we go to the NodeJS official site at https://nodejs.org/, we will see that there are two releases going on and they are LTS (Long Term Support) and Current. The LTS version currently is 14.18.1 and Current is 17.0.1.

    LTS is the stable version that goes through a lot of testing, and has a 30-month development cycle. Anything new that is added to this version will only be the bug fixes during this window. There will be no new features added to Node in this version. As per the NodeJS official site also, this version is recommended for most users. This is the version which is preferred by Enterprise users as they do not want to run into any issues in their large production projects.

    The other version is the Current version, which is a step ahead of the LTS version. In this version new features are added to the Node language. Sometimes these new features break a lot of things, but mostly they are newer features than those that are available in the LTS version. The current version is preferred by hobbyist programmers or small start-ups which want to work with innovative technologies.

    Node Version Manager (NVM)

    Node.js is an open-source project and there are times when we need one version over the other. Suppose we have a stable Production project, which is using the old LTS version. At the same time, we are working on a side-project, which needs the latest NodeJS Current version. In this case we must keep on deleting one Node version, working on the project, and returning to the other version for the other project.

    This is a very common problem and the best solution is to use nvm (Node.js Version Manager). It lets us switch between different versions of Node without much efforts. We will now understand through examples, how easy it is to switch, install and remove node versions on a system.

    Installing NVM on Linux

    The installation of nvm on Linux is mainly done through the command line. We are going to illustrate how to install nvm on Ubuntu, but you may note that a similar process can be followed for different flavours of Linux.

    I am using Ubuntu through WSL (Windows Subsystem for Linux), but the process is the same in an Ubuntu system also.

    Open the Ubuntu terminal and install wget through the package manager for Ubuntu known as ap-get. Through apt-get, we can easily install any package on an Ubuntu system.

    We are using the sudo apt-get install wget command. We have to use sudo because to install wget or any other packages, we need admin privileges. It might also ask for a password the first time and we have to give the admin or root password to proceed.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    Once wget is installed give the below command to install nvm on the Linux system.

    wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

    After the command is complete, we will get further commands to properly install nvm on our Linux system.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    We will run the given three commands separately from the terminal.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Next, we will install a node.js version through nvm. Later on, we will see all the commands in more detail. We are using the command nvm install 14.8.1 to install a node version.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Once it is installed, we can see the versions of node.js installed on our Ubuntu system by giving the nvm ls command.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Installing NVM on macOS

    The installation of nvm on mac is mainly done through command line and there are many different ways to do this. But we will follow the brew way, in which we install nvm through the macOS brew command.

    We need to install Homebrew first to proceed. It is an open-source manager for macOS, which makes it easier to install any software through the command line in macOS. The command to be given on a terminal is shown below. Also make sure that you are using the default bash shell, as this command will give an error in fish or csh shell.

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

    It will also ask us for the root password.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Once you give the root password the installation will start.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    There are two ways to install nvm, one is through wget and other is through curl. We need to install these through brew.

    We can install wget in our mac through the command brew install wget command.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Once wget is installed give the below command to install nvm on the mac system.

    wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    We can also install curl through brew by giving the command brew install curl in the terminal.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    The command to install nvm through curl is below.

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

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Both of these installs through wget or curl, will tell us to run the below command on a Mac to install nvm in our shell.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    So, we need to give these two commands from the terminal to install nvm properly on our mac system.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    The nvm commands to install and use it are the same on Ubuntu, mac and windows and we will see them in detail later. But we will install a version of node.js on mac to check if it is working properly. We are installing version 14.8.1 through the command nvm install 14.8.1 on our terminal.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Now, if we do nvm ls on our terminal, we can see this version along with the other versions installed on our macos system.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Installing NVM on Windows

    The installation process for Windows is totally different from MacOS. We will learn to do the same on Windows now, which requires the package nvm-windows. So, first go to https://github.com/coreybutler/nvm-windows/releases and click on nvm-setup.zip file.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Once the zip file is downloaded, then extract it. It will be extracted as a single nvm-setup.exe file. Click on the same and the screen for Licence Agreement will appear, as below. But we will also be asked to trust this app in the Windows login screen.

    Click on “I accept the agreement” and then the Next button.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    It will give us a destination to install NVM, which we can keep as it is and click on the Next button.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Next, it will ask us for the folder to create the Symlink, which we can keep and again click on the Next button.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Finally, it will ask us to Install nvm and we can click the Install button now.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    This will install NVM on your machine. But if you have already installed a version of Node.JS prior to installing NVM, it will ask us for permission to control it. Click on Yes in the pop-up.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    After NVM is installed successfully, we will get the below screen. We now must click on the Finish button.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    To verify that the nvm was installed properly, run the command nvm –version from the Windows Terminal and we will get a long list of outputs showing that it was installed.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    Using NVM

    There are various commands which we can use with nvm and change and install any version of node.js with ease. The commands are the same on Windows, MacOS or Linux. The first thing which we must do is to check the versions of node.js installed on the machine. We can do this by using the nvm ls command.

    As seen in the output, it gives us all the node versions installed on my machine.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    The most useful command is the nvm install command. Now, this can be used in two ways. We can use it as below –

    • nvm install latest – To install the latest version of node.js
    • nvm install <version number> - To install any version of node.js

    We are using both commands to install the latest and a previous version of node.js

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    Now, running the nvs ls command will show all of the versions, available on the machine.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    To use a different version, we just have to use the nvm use command and give the version number. To use the version 17.0.1 in our case, we will give the command nvm use 17.0.1 in terminal. You might get an error like below if you are running this command as a non-admin user.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    To solve this issue, run the command prompt as an Administrator.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)

    Now, again use the nvm ls command and we will see that the 17.0.1 version is in use.

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    We can also uninstall any version of node.js with the nvm uninstall <version> command.

    Are you ready to unlock the power of Python? Join our unique and engaging Introduction to Python course and discover the endless possibilities of this versatile programming language. Start your coding journey today!

    Installing and Managing Node.JS Using Node Version Manager (Nvm)
    Summary

    This article first introduced you to the different Node.JS versions and emphasized the importance of NVM. Next, you learnt how to install it on Ubuntu, then on MacOS and finally on Windows. Lastly, you have learnt about the different commands to install, use and check Node.JS versions. Good luck on your learning journey!

    Profile

    Sachin Bhatnagar

    Blog Author

    Sachin Bhatnagar is an experienced education professional with 20+ years of expertise in Media & Entertainment and Web Technologies. Currently, as the Program Director - Full-Stack at KnowledgeHut, he excels in curriculum development, hands-on training, and strategic deployment of industry-centric educational programs. His online training programs on have attracted over 25,000 learners since 2014. He actively contributes to the development of full-stack training products, leveraging KnowledgeHut's advanced learning platform. Collaborating with organizational leaders, he ensures the success of these programs and has created several technology programs prominently featured in KnowledgeHut's course offerings.

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming Web Development Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon