How to install Node.js locally with nvm?
© https://nodejs.org/en/

How to install Node.js locally with nvm?

Manage multiple versions of Node.js.

ByMario Kandut

honey pot logo

Europe’s developer-focused job platform

Let companies apply to you

Developer-focused, salary and tech stack upfront.

Just one profile, no job applications!

This article is based on Node v16.14.0.

Using the Node.js Version manager (nvm) makes installing and managing multiple versions of Node.js on a single local environment easy. I can only recommend using nvm, even if you only need one single version of Node.js, there is a high chance it won't stay like this and switching between different versions is easy.

Node.js Version Manager (NVM)

💰 The Pragmatic Programmer: journey to mastery. 💰 One of the best books in software development, sold over 200,000 times.

nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. It is the preferred way to manage Node.js locally. In a production environment use the operating system package manager, or a server tooling to install and lock your specific version of Node.js.

How to install NVM

nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.

To install or update nvm, run the install script. You can also download it and then run it, but cUrl or Wget with bash pipe are very convenient commands.

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

or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Running either of the above commands downloads a script and runs it. This script clones the nvm repository into ~/.nvm and updates your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) to source the nvm.sh it contains.

After this restart your terminal or manually source your ~/.profile, like source ~/.bash_profile.

Then verify that it worked, with the command:

command -v nvm

The command should return nvm. Normally we could use which, but nvm is a shell script and not an application.

Some common trouble shooting tips can be found in the official documentation of nvm.

How to use nvm

After successful installation, we can type in nvm to get a list of available commands. We start with installing the latest LTS version of Node.js.

nvm install --lts

The output should look similar like this:

Installing latest Node.js version with NVM

The last line says now using node v14.7.0, which means that nvm is set to use Node.js version 14.7.0. We can verify by typing node --version.

If you want to install a different Node.js version, just use nvm ls-remote to list all versions and install it nvm install <VERSION>, would be a placeholder for the version number. After installing it, you have to tell nvm to use it with nvm use <VERSION>. Verify with node -v.

TL;DR

  • nvm is an easy way to manage multiple versions of Node.js
  • nvm is a shell script and invoked per shell.
  • Install a Node.js version with nvm install <VERSION>
  • Use an installed Node.js version with nvm use <VERSION>

Thanks for reading and if you have any questions, use the comment function or send me a message @mariokandut.

If you want to know more about Node, have a look at these Node Tutorials.

References (and Big thanks):

Node.js, HeyNode

More node articles:

Getting started with Webpack

How to list/debug npm packages?

How to specify a Node.js version

How to create a web server in Node.js

How to dynamically load ESM in CJS

How to convert a CJS module to an ESM

How to create a CJS module

How to stream to an HTTP response

How to handle binary data in Node.js?

How to use streams to ETL data?

How to connect streams with pipeline?

How to handle stream errors?

How to connect streams with pipe?

What Is a Node.js Stream?

Handling Errors in Node (asynchronous)

Handling Errors in Node.js (synchronous)

Introduction to errors in Node.js

Callback to promise-based functions

ETL: Load Data to Destination with Node.js

ETL: Transform Data with Node.js

ETL: Extract Data with Node.js

Event Emitters in Node.js

How to set up SSL locally with Node.js?

How to use async/await in Node.js

What is an API proxy?

How to make an API request in Node.js?

How does the Event Loop work in Node.js

How to wait for multiple Promises?

How to organize Node.js code

Understanding Promises in Node.js

How does the Node.js module system work?

Set up and test a .env file in Node

How to Use Environment Variables in Node

How to clean up node modules?

Restart a Node.js app automatically

How to update a Node dependency - NPM?

What are NPM scripts?

How to uninstall npm packages?

How to install npm packages?

How to create a package.json file?

What Is the Node.js ETL Pipeline?

What is data brokering in Node.js?

How to read and write JSON Files with Node.js?

What is package-lock.json?

How to install Node.js locally with nvm?

How to update Node.js?

How to check unused npm packages?

What is the Node.js fs module?

What is Semantic versioning?

The Basics of Package.json explained

How to patch an NPM dependency

What is NPM audit?

Beginner`s guide to NPM

Getting started with Node.js

Scroll to top ↑