Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Development Last updated: July 13, 2023
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

Node.js is a cross-platform, open-source JavaScript runtime environment that runs on Chrome’s V8 JavaScript engine and allows you to execute JavaScript code outside the context of a web browser, such as on the server side. This makes Node.js an ideal tool for developers to use when creating server-side applications.

Node.js has become so popular that it was ranked as the most popular web framework among professional developers and developers learning to code in the Stack Overflow Developer Survey.

software-developer-6521720_1920

Since Node.js is continuously being developed and improved upon, new versions of Node.js get released from time to time. This often results in new features being added to the framework, some older features being deprecated, or even changes in how certain functionalities are implemented in the framework.

This means that as developers build applications using Node.js, these applications get implemented using different versions of Node.js.

This, in turn, means that an application implemented using a particular version of Node.js, such as Node.js version 9.x may yield unexpected results or generate errors when you try to run it using a different version of Node.js such as Node.js 20.x.

To solve this, you’d have to keep uninstalling your current Node.js version and installing the required Node.js version as you work with different Node.js projects.

In a normal work environment, a developer may be required to do this multiple times as they switch between projects, which can quickly become very painful and tiring. Luckily, there’s a better way to do this by using the Node Version Manager (NVM).

Nodejs-Frequently-Asked-Interview-Questions

The Node Version Manager(NVM) is a command-line tool that allows you to install and manage multiple versions of Node.js on your machine. Additionally, it allows you to easily switch between the different Node.js versions that have been installed on your machine. This makes nvm an essential tool for anyone working with Node.js, even if they are yet to work on projects using different Node.js versions.

Let’s dive into how you can install nvm on Windows or MacOS.

Prerequisites for installing NVM

Before installing nvm, ensure that you uninstall any existing Node.js versions to avoid conflicts after you install nvm. If you’re using Windows, go ahead and also delete the directory where Node.js had been installed on your machine. This usually is the nodejs folder found inside program files

When installing nvm on MacOS, you need to ensure that you manually install Xcode command line tools before trying to install nvm.

Otherwise, the installation will fail. This article will cover how to do this in the section on how to install nvm on macOS. Installing Xcode command line tools requires MacOS version 13 or later and about 2.5GB of free disk space.

How to Install NVM on Windows

The original Node Version Manager was made for Linux and Mac operating systems and not Windows. In that regard, the NVM we are going to install on Windows is a bit different from the nvm used on Linux and Mac.

However, it is the NVM that is recommended for Windows operating systems by Microsoft and Google.

To install NVM on your Windows computer, follow the following steps

1. Go to nvm releases to see the nvm releases. Under Assets, click on the latest nvm-setup.exe to download the latest nvm installer.

Assets1

2. Once the download is complete, open the installer and Select Yes when asked whether you want to allow the app to make changes to your device or not.

3. On the License Agreement Screen, select I accept the agreement then click Next

License2

4. On the Select Destination Location screen, specify where you want nvm for Windows to be installed and click on Next

Location3

5. On the Set Node.js Symlink screen, specify where you want the Symlink to be set up the click on Next. This is where the active version of Node.js will be found.

Symlink4

6. With everything set up, it is now time to install nvm. On the Ready to Install screen, click on Install to install nvm on your machine.

Install5

7. Once the installation process is done, click on Finish

Finish6

8. To confirm the installation was complete, Open Windows PowerShell and Run it as an Administrator

Powershell7

9. Once in Powershell, execute

nvm -v

If the installation was successful, you should see a screen with the version number of the nvm you installed.

Version8

With nvm installed, you can go ahead and use it to install and manage multiple versions of Node.js

How to Install NVM on macOS

When installing nvm on MacOS, it is recommended that you install it directly from GitHub and not by using Homebrew, the package manager for macOS. Additionally, you need to manually install the Xcode command line tools on your machine. Therefore, our first steps will cover how to install Xcode command line tools. To do this, follow the following steps:

1. Go to the Apple developers’ download page

2. Search for Command Line Tools for Xcode. Download the latest version that is not a beta version or Release candidate

Screen-Shot-2023-07-12-at-21.49.50

3. Open the downloaded .dmg file and run the Command Line tools.pkg file. This starts with the command line tools installer.

pkg

4. Click Continue

1-2

5. Click Continue. You can also change your preferred language on this screen.

2-1

6. Click on Agree to continue with the installation, then Click on Install to install the command line tools.

3-1

Once command line tools have been installed, the next step is to install nvm on Mac. For this, follow the following steps:

  1. Open your terminal and check whether your Mac’s home directory has a .zshrc by executing
ls -a

2. In case you don’t see a .zshrc file in your home directory, create one by executing

touch ~/.zshrc

3. Copy the following command into your terminal and execute it:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Screen-Shot-2023-07-12-at-22.12.09

The above command downloads a script and runs it. The script clones the nvm repository, thus installing nvm in your Mac.

To confirm that nvm has been run, the following command in your terminal

nvm -v

If you are presented with a version number, the installation was successful.

Conclusion

The node version manager is an essential tool for developers working with Node.js as it allows you to easily work with different Node.js versions, manage the versions, and switch between the different versions easily. If you are a developer working with the Node.js framework, consider installing nvm on your computer.

You may also explore how to Install Node.js and NPM on Windows and macOS.

  • Collins Kariuki
    Author
    Collins Kariuki is a software developer and technical writer for Geekflare. He has over four years experience in software development, a background in Computer Science and has also written for Argot, Daily Nation and the Business Daily Newspaper.
  • Narendra Mohan Mittal
    Editor

    Narendra Mohan Mittal is a Senior Digital Branding Strategist and Content Editor with over 12 years of versatile experience. He holds an M-Tech (Gold Medalist) and B-Tech (Gold Medalist) in Computer Science & Engineering.


    read more
Thanks to our Sponsors
More great readings on Development
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Monday.com is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder