Install Node.js Locally with Node Version Manager (nvm) (2024)

Using nvm (Node.js Version Manager) makes it easier to install and manage multiple versions of Node.js on a single local environment. Even if you only need a single version of Node.js right now, we still recommend using nvm because it allows you to switch between different versions of Node (depending on the requirements of your project) with minimal hassle.

In this tutorial, we'll walk through:

  • How to download and install the Node Node Version Manager (nvm) shell script
  • Using nvm to install the latest LTS version of Node.js
  • Switching to a different Node.js version with nvm

By the end of this tutorial, you should be able to install the nvm command and use it to manage different versions of Node.js on a single environment.

Goal

Install and manage a local installation of node using nvm.

Prerequisites

  • Overview: Manage Node.js Locally

Watch

Install nvm

NVM stands for Node.js Version Manager. The nvm command is a POSIX-compliant bash script that makes it easier to manage multiple Node.js versions on a single environment. To use it, you need to first install the bash script, and add it to your shell's $PATH.

Learn more about why we recommend using NVM in Overview: Manage Node.js Locally.

Note: We do not recommend using nvm to install Node.js for production environments. If you're installing Node.js on your production environment you should consider using your OS's package manager, or your server tooling of choice, to install and lock the environment to a specific version of Node.js.

The official documentation for how to install nvm, and some common trouble shooting tips, is in the project's README.

Windows users: The process for installing nvm on Windows is different than what's shown below. If you're using Windows check out this Windows-specific version of nvm.

The basic process is as follows:

Download the install script

Using curl, or wget, download the installation script. In the URL below make sure you replace v0.35.0 with the latest version of nvm.

curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh

It's not a bad idea to open the install script and inspect its contents given that you just downloaded it from the Internet.

Run the install script

Run the install script with bash.

bash install_nvm.sh

This script clones the nvm repository into ~/.nvm. Then it updates your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) to source the nvm.sh it contains.

You can confirm that your profile is updated by looking at the install script's output to determine which file it used. Look for something like the following in that file:

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

Restart your terminal

In order to pick up the changes to your profile either close and reopen the terminal, or manually source your respective ~/.profile.

Example:

source ~/.bash_profile

Verify it worked

Finally, you can verify that it's installed with the command command:

command -v nvm

Should return nvm. Note: You can't use the which command with nvm since it's a shell function and not an actual application.

See what it does

Finally, run the nvm command to get a list of all the available sub-commands and to further verify that installation worked.

Use nvm to install the latest LTS release of Node.js

Now that you've got nvm installed let's use it to install, and use, the current LTS version of Node.js.

nvm install --lts
# OutputInstalling latest LTS version.Downloading and installing node v10.16.3...Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-darwin-x64.tar.xz...######################################################################## 100.0%Computing checksum with sha256sumChecksums matched!Now using node v10.16.3 (npm v6.9.0)Creating default alias: default -> lts/* (-> v10.16.3)

Verify it worked, and that the version is correct:

node --version# => v10.16.3which node# => /Users/joe/.nvm/versions/node/v10.16.3/bin/node

Note this line Creating default alias: default -> lts/* (-> v10.16.3). This indicates that nvm has set lts/* as the default alias. Practically this means that anytime you start a new shell, and the nvm.sh script is sourced, it will default that shell to using the installed lts release. You can change this behavior using the nvm alias command.

Example to set the default version of node to use when starting a new shell to 10.0.0:

nvm alias default 10.0.0

Use nvm to install other versions of Node.js

The real benefit of nvm comes when you install different versions of Node.js. You can then switch between them depending on which project you're working on.

List available versions

To see the entire list of Node.js versions available to install, enter the following:

nvm ls-remote

Install a specific version

Install a specific version:

nvm install 8.16.2

Install the latest release:

nvm install node

Install an older LTS release by codename:

nvm install carbon# => Installs v8.16.2 the latest release of the Carbon LTS line.

List installed versions

You can see which versions of Node.js you have installed already, and therefore which ones you can use with the nvm ls command:

nvm ls

This will output a list of installed versions, as well as indicate which version is currently being used by the active shell.

Switch to another version

To switch to another version for the active shell use nvm use.

For a specific version provide a version number:

nvm use 10.16.3# => Now using node v10.16.3 (npm v6.9.0)

Switch to the latest installed version:

nvm use node

Use the latest LTS version:

nvm use --lts

Tip: Use nvm alias default {VERSION} to switch the version of Node.js used by default when starting a new shell.

Recap

In this tutorial we walked through installing the nvm bash script and making sure it works. Then we used nvm to install the latest LTS release of Node.js and set it as our environment's default Node.js version. Then we looked at how you can use nvm to install any number of Node.js versions and switch between them as needed.

You should now be all set to execute and work on your your Node.js project(s) no matter which version of Node.js they are written for.

Further your understanding

  • Run the nvm command with no arguments and read through the list of sub-commands that we didn't cover in this tutorial. What did you find? What might they be useful for?
  • Can you figure out how to switch to the version of Node.js that your OS came with?
  • Why would you want to change to a different version of Node.js while doing development?
  • What happens when you install an npm package globally (e.g. npm install -g express) while using NVM to manage Node.js versions?

Additional resources

Install Node.js Locally with Node Version Manager (nvm) (2024)
Top Articles
Nvidia Is the Hottest Stock-Split Stock on Wall Street. The Artificial Intelligence (AI) Company Could Be Worth $10 Trillion by 2030 | The Motley Fool
How to improve revenue cycle management
Lairson Enterprises Rv Sales
Magickwoods Elements Brighton
Craigslist Org Hattiesburg Ms
3Movierulz
Trauma Care | FMOLHS
Keyn Car Shows
Intermountain Healthcare Roy
Tax Bd Casttaxrfd
Wrongplanet.net
Joy Studio Yupoo
Oldeuboi Showtimes Near Marcus Ronnie's Cinema
U-M athletic director: Former M Den retailer bounced a $3.8M check
Chase Field Ticket Office Hours
Post Game Contents and 100 Percent Guide | Zelda: Skyward Sword HD (Switch)|Game8
Lakeview Docks Jet Ski Rentals
The 36 best Chicago attractions
The Self Directed Learning and Assessment Route | CIMA
Www Walmart Career Application Com
Csusm Verify My Fafsa
Best Bars Near Comerica Park
Fiat E-Ducato im Test: Elektrischer Transporter auf Lorbeerruhe
Gross Net Salary Calculator Germany - 2024
Cvs Minuteclinic Locations Near Me
Milwaukee Nickname Crossword Clue
27L1576
Cranes Lane, Ormskirk L40 3 bed end of terrace house to rent - £1,495 pcm (£345 pw)
855 700 4473
Wedding Dr Amy Hutcheson Married
Sam's Club Near Wisconsin Dells
714-603-0170
Milwaukee Zoo Ebt Discount
Huff Lakjer Funeral Home
An Aisle Connecting Rooms In Western Tower
The Front Porch Self Service
How to Use Craigslist (with Pictures) - wikiHow
Bhcu Login
Gina Wilson All Things Algebra Unit 3 Homework 2
866-308-1159
Leonard Trailers Summerville Sc
Ellafeet.official
Master’s degree programmes
Beatles Jrpg
Strip Clubs In Bowling Green
Gander Rv Hamburg Ny
How Long Does A Rock Live
Unified Communications Certificate (UCC): A Comprehensive Guide - SSL.com
Photos Body Gigi Autopsy Sketch
Dalmatian Puppies For Sale Craigslist
Game Akin To Bingo Nyt
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 5781

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.