NVM Handbook — Running multiple Node.js versions on Windows, Linux, and macOS

RAJ KUMAR KAUSIK
4 min readSep 17, 2023

--

Node.js is a popular JavaScript runtime environment used for developing server-side applications and command-line tools. To manage multiple Node.js versions on your system effortlessly, you can use the Node Version Manager (NVM). In this article, we will walk you through the installation process for NVM and Node.js on three major operating systems: Windows, Linux, and macOS.

Installing NVM and Node.js on Windows

Installing NVM on Windows might seem a bit different from other platforms due to the lack of native support. However, you can use the “nvm-windows” project, which is a Windows version of NVM. Here are the steps:

1. Download NVM for Windows:
— Visit the official “nvm-windows” repository on GitHub at [https://github.com/coreybutler/nvm-windows](https://github.com/coreybutler/nvm-windows).
— Download the latest installer by clicking on the “nvm-setup.zip” link.

2. Install NVM:
— Run the downloaded installer.
— Follow the installation wizard, which will guide you through the setup process.

3. Open a New Command Prompt:
— Close and reopen any existing command prompt windows.
— To check if NVM is installed, run `nvm version` in the command prompt.

4. Install Node.js:
— To install the latest Node.js version, run `nvm install node`.
— To use Node.js, type `nvm use node`.

Installing NVM and Node.js on Linux

Linux offers a straightforward process for installing NVM and Node.js. Here are the steps:

1. Open a Terminal:

- Open your terminal emulator. You can typically find it in your applications menu.

2. Install NVM:

- Open your terminal and use the following command to install NVM:

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

This command downloads and runs the NVM installation script.

3. Close and Reopen the Terminal:

- Close the terminal window and open a new one to apply the changes.

4. Install Node.js:

- To install the latest Node.js version, run:
nvm install node
— To use Node.js, type:
nvm use node

Installing NVM and Node.js on macOS

Installing NVM and Node.js on macOS is similar to the process on Linux. Follow these steps:

1. Open a Terminal:

- Launch the Terminal application on your macOS system.

2. Install NVM:

- Use the following command to install NVM:

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

3. Close and Reopen the Terminal:

- Close the terminal window and open a new one for the changes to take effect.

4. Install Node.js:

- To install the latest Node.js version, run:
nvm install node
— To use Node.js, type:
nvm use node

Congratulations! You’ve successfully installed NVM and Node.js on Windows, Linux, and macOS. You can now develop and run Node.js applications with ease, and easily switch between different Node.js versions based on your project requirements.

Installing a Specific Version of Node.js

Replace `x.y.z` with the specific version number you want to install.

Windows:

1. Open a Command Prompt and run the following command to install a specific version of Node.js:
nvm install x.y.z

2. To use the installed version, run:
nvm use x.y.z

Linux and macOS:

1. Open a Terminal and run the following command to install a specific version of Node.js:
nvm install x.y.z

2. To use the installed version, run:
nvm use x.y.z

Verifying the Installed Node.js Version

After switching to the desired Node.js version, you can verify the installation by running:
node -v

This command will display the specific version of Node.js you installed.

Setting a Default Node.js Version

If you want to set a default Node.js version to be used across all your projects, you can do so with NVM:

Windows:

1. Open a Command Prompt and run:
nvm alias default x.y.z

Linux and macOS:

1. Open a Terminal and run:
nvm alias default x.y.z

Replace `x.y.z` with the version number you want to set as the default.

Now, when you open a new terminal or command prompt, it will use the default Node.js version you specified.

By following these steps, you can easily install and work with a specific version of Node.js using NVM on Windows, Linux, and macOS, and manage different Node.js versions for your projects.

Bonus

1. Updating NVM and Node.js

It’s important to keep your development environment up to date. You can update NVM and Node.js using the following commands:

Update NVM:

- Windows:
nvm-windows-updater

- Linux and macOS:
nvm install-latest-npm
nvm install-latest-npm — reinstall-packages-from=x.y.z

Replace `x.y.z` with your current Node.js version.

Update Node.js:

- To update Node.js to the latest version, you can simply run:
nvm install node — reinstall-packages-from=node

2. Using `.nvmrc` Files

Create a `.nvmrc` file in your project’s root directory and specify the Node.js version your project requires. Then, you can use the `nvm use` command without specifying the version each time you switch to your project directory:

bash
# Inside your project directory, create or edit .nvmrc
echo “x.y.z” > .nvmrc

Now, when you navigate to your project directory, simply run `nvm use` to automatically switch to the specified Node.js version.

3. Global NPM Packages

After installing a Node.js version, you may want to install global NPM packages. Be aware that these packages are version-specific and might need to be reinstalled when you switch to a different Node.js version.

Conclusion

Installing NVM and Node.js on Windows, Linux, and macOS is essential for efficient Node.js development. NVM simplifies the process of managing multiple Node.js versions and allows you to switch between them effortlessly.

By following the installation steps outlined in this guide, you can set up NVM and Node.js quickly. Moreover, with the bonus tips provided, you can enhance your development workflow, keep your Node.js environment up to date, and easily manage Node.js versions for your various projects.

With NVM in your toolkit, you have the flexibility and control to work with specific Node.js versions for different projects, ensuring compatibility and optimal performance. Happy coding!

--

--