Hostomy Blog

How to Install Node Version Manager (NVM) on Ubuntu 24.04

Dec 05, 2024

By Rahul Mukati

Rahul Mukati
How to Install Node Version Manager (NVM) on Ubuntu 24.04

Node Version Manager (NVM) is an excellent tool for developers who need to work with multiple versions of Node.js on a single machine. It allows you to seamlessly switch between Node.js versions, ensuring your development environment is always aligned with your project requirements.

In this guide, we’ll show you how to install and use NVM on Ubuntu 24.04. If you’re looking for a reliable cloud server to get started, check out Hostomy Cloud Servers.

Why Use NVM?

NVM offers several advantages:

  1. Switch Node.js versions easily: Ideal for working on projects requiring different versions.
  2. Isolated environments: Manage multiple Node.js versions without conflicts.
  3. Simplicity: Install and manage Node.js directly from the command line.

Step 1: Update Your System

Before installing NVM, ensure your system is up-to-date:

sudo apt update && sudo apt upgrade -y  

Step 2: Install Required Packages

NVM requires curl and build-essential. Install them using:

sudo apt install curl build-essential -y  

Step 3: Download and Install NVM

Use the official NVM installation script to install NVM:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash  
Note: Replace v0.40.1 with the latest version from the NVM GitHub repository.

Step 4: Load NVM

After installation, load NVM into your current shell session:

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"  

To make this persistent across sessions, add the following lines to your ~/.bashrc or ~/.zshrc file:

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"  

Then reload your shell:

source ~/.bashrc  

Step 5: Verify NVM Installation

Check if NVM is installed correctly:

nvm --version  

If you see the version number, NVM is successfully installed!

Step 6: Install and Use Node.js

Install the Latest Node.js Version

nvm install node  

Install a Specific Version

Replace x.x.x with the desired version:

nvm install x.x.x  

Set a Default Version

nvm alias default x.x.x  

Switch Node.js Versions

nvm use x.x.x  

List Installed Versions

nvm list  

Step 7: Install npm Packages for Specific Projects

Since each Node.js version has its isolated npm environment, you can install project-specific dependencies without interference.

Why Choose Hostomy for Your Development Environment?

For smooth development, deploy your project on a high-performance Hostomy Cloud Server. Enjoy:

  • Reliable uptime.
  • Affordable pricing.
  • Scalability to meet your project’s needs.

Conclusion

NVM simplifies managing Node.js versions, especially when working on multiple projects with varying requirements. Follow this guide to install NVM on Ubuntu 24.04, and you’ll be up and running in no time.

For a seamless experience, pair your development environment with a Hostomy Cloud Server today! 🚀