Sign In
Sign In

Installing and Using NVM (Node Version Manager)

Installing and Using NVM (Node Version Manager)
Hostman Team
Technical writer
Node.js
17.07.2024
Reading time: 3 min

Node Version Manager (NVM) is a powerful tool designed to manage multiple versions of Node.js on a single machine. It simplifies the process of installing, updating, and switching between different versions of Node.js, making it an essential tool for developers working on various projects with different Node.js requirements.

Benefits of Using NVM

  • Version Management: Easily install and switch between different versions of Node.js.

  • Environment Isolation: Maintain separate Node.js versions for different projects.

  • Convenience: Simplifies testing and development by providing quick version switching.

Installing NVM

To install NVM, follow these steps:

1. Download and Install Script

Open a terminal and run the following command to download and install NVM:

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

Output:

Image2

2. Load NVM

After the installation, you need to add NVM to your shell profile. Run the following command:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

3. Verify Installation

Ensure that NVM is installed correctly by checking its version:

nvm --version

Output:

Image4

Installing Node.js Versions with NVM

With NVM installed, you can now install different versions of Node.js.

1. Install a Specific Version

To install a specific version of Node.js, use the following command:

nvm install <version>

Replace <version> with the desired Node.js version number (e.g., 14.17.0).

Output:

Image3

2. Install the Latest LTS Version

To install the latest Long-Term Support (LTS) version of Node.js, run:

nvm install --lts

Output:

Image6

Switching Between Node.js Versions

NVM allows you to switch between installed Node.js versions easily.

1. List Installed Versions

To view all installed Node.js versions, use:

nvm ls

Output:

364c647c 1f50 4f27 B848 D8159b649a77

2. Switch to a Specific Version

To switch to a specific version, run:

nvm use <version>

Image1

Replace <version> with the version number you want to use.

Setting a Default Node.js Version

You can set a default Node.js version that will be used in all new shell sessions.

Set Default Version

To set a default Node.js version, use:

nvm alias default <version>

Replace <version> with the desired Node.js version number.

Uninstalling Node.js Versions with NVM

NVM also provides an easy way to uninstall Node.js versions that are no longer needed.

Uninstall a Specific Version

To uninstall a specific Node.js version, run:

nvm uninstall <version>

Replace <version> with the version number you want to uninstall.

Conclusion

Using NVM (Node Version Manager) simplifies the management of multiple Node.js versions, providing a convenient and efficient workflow for developers. By following the steps outlined in this tutorial, you can easily install, switch, and manage different Node.js versions on your system.

This tutorial provides a comprehensive guide to installing and using NVM, ensuring a smooth and efficient Node.js version management experience.

Node.js
17.07.2024
Reading time: 3 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us