Karpton Logo

How to Install Node Version Manager

Written by Toni Karppi on

Node Version Manager is a utility for managing multiple versions of Node. This comes in handy when you are working on projects that are only known to work on particular Node versions. In this tutorial, we’ll go through how to install and use NVM.

Installing Node Version Manager

First we’ll have to download and run the installation script.

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

This is the same command as found in the project README. You may want to adjust the version number, in case there has been a new release since this article was published.

The next step depends on whether you’re using ‘bash’ or ‘zsh’ as your shell.

Using Bash

The script above adds the following lines to ~/.bashrc:

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

This makes nvm accessible through the shell. Before we can call the nvm utility, we need to either reopen the terminal window, or enter:

source ~/.bashrc

Using ZSH

I’ll be assuming that you’re running ZSH with oh-my-zsh. In this case we can just use the nvm plugin, which takes care of the sourcing for us. Add the ‘nvm’ plugin to your plugins array in ~/.zshrc.

plugins=(
  nvm
)

To make nvm accessible though the shell, we can either reopen the terminal window, or enter:

source ~/.zshrc

Using Node Version Manager

At this point, you should have access to nvm in your shell. To check this, enter:

nvm --version

To check what commands are available, enter:

nvm --help

Let’s start with listing all available versions of Node:

nvm ls-remote

If you’re only interested in LTS versions, then you can enter

nvm ls-remote --lts

Let’s install the latest LTS as of this writing, v10.16.0.

nvm install v10.16.0

Now the activated version of node should be v10.16.0. To check this, enter:

node --version

Let’s also install the latest non-lts version of node.

nvm install v12.4.0

Now the activated version of node should be v12.4.0.

node --version

You can see the locally installed versions of node with:

nvm ls

To switch back to the LTS, enter:

nvm use v10.16.0

Now the activated version of node should be v10.16.0.

What’s next

Now you’ve seen the commands that I find to be the most useful with NVM. If you want to explore other stuff that you can do with NVM, check the output from the help command. Thanks for reading!