Installing NVM on Ubuntu

Node Version Manager (NVM) is a powerful tool that allows you to install, manage, and switch between multiple Node.js versions on your system with ease. NVM is especially useful for developers who work with multiple Node.js projects, each requiring different Node.js versions. This article will guide you through the process of installing NVM on an Ubuntu system and demonstrate its basic usage.

Section 1: Prerequisites

Before installing NVM on your Ubuntu system, ensure that you have the following:

  1. A computer running Ubuntu (version 18.04 or later is recommended).
  2. Access to a terminal and a user account with sudo privileges.

Section 2: Installing NVM

To install NVM on your Ubuntu system, follow these steps:

Step 1: Update your system packages

Open a terminal and run the following command to update your system packages:

sudo apt update

Step 2: Install dependencies

NVM requires some basic dependencies, such as build-essential, libssl-dev, curl, and git. Install them by running the following command:

sudo apt install build-essential libssl-dev curl git -y

Step 3: Download and run the NVM installation script

NVM can be installed by running a shell script provided by the NVM project. To download and run the script, use the following command:

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

Note: Replace v0.39.1 with the latest NVM version available at the time of installation. You can check the latest version on the NVM GitHub repository.

Step 4: Activate NVM

To activate NVM in your current terminal session, run the following command:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Alternatively, close and reopen your terminal to load NVM automatically.

Section 3: Using NVM

Now that NVM is installed, you can start managing Node.js versions. Here are some basic NVM commands:

  1. List available Node.js versions:
nvm ls-remote
  1. Install a specific Node.js version:
nvm install <version>

For example, to install Node.js version 16.13.0, run:

nvm install 16.13.0
  1. List installed Node.js versions:
nvm ls
  1. Switch between installed Node.js versions:
nvm use <version>
  1. Set a default Node.js version:
nvm alias default <version>
  1. Uninstall a Node.js version:
nvm uninstall <version>

Section 4: Updating NVM

To update NVM to the latest version, you can run the installation script again:

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

Don’t forget to replace v0.39.1 with the latest version.

Conclusion

In this article, we’ve learned how to install and use NVM on an Ubuntu system. With NVM, you can easily manage multiple Node.js versions and switch between them as needed for your projects.

Facebook
Twitter
LinkedIn
Pinterest

Related posts