How To Install or Update Node by Using nvm (Node Version Manager)
Tags: javascript, node
Published: 2021-05-09 18:01:20

---
title: "How To Install or Update Node by Using nvm (Node Version Manager)"
tags: ["javascript", "node"]
keywords: ["javascript", "node", "nvm"]
published: true
canonical_url: "https://byte.ski/blog/article/how-to-install-or-update-node-by-using-nvm"
cover_image: "https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7hsgozff830lrvptb0t.png"
---

***Subscribe to my email newsletter to stay up to date.***

<a href="https://byte.ski/newsletter"><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fld1yqfgvgz2dgcpho0x.png" alt="subscribe" /></a>

## Intro

There are few ways to install [Node](https://byte.ski/notes/Node) on your local machine. The most popular way is to install it following [official website instructions](https://nodejs.org/en). But if you use this way you will install just one specific (latest) version of Node. What if you need to install a specific version of Node? Or you need to upgrade from one version to another but only for a short while. 

For that purpose, you can use a tool called **nvm** ([Node Version Manager](https://byte.ski/notes/Node-Version-Manager)).

## Installation

Because I use **macOS** on my local machine these instructions are specific to that operating system. You can find instructions that are specific to an operating system that you use on [official documentation on GitHub](https://github.com/nvm-sh/nvm).

To install **nvm** on your local machine let's use this command:

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

Now let's type the command which tells us that nvm is installed and available on our local machine:

```
nvm --version
```

You should see the current version of [Node Version Manager](https://byte.ski/notes/Node-Version-Manager) that is installed on your local machine.

### Shell Troubleshooting

If you use some shell as [Z shell](https://byte.ski/notes/Z-shell) or [Fish Shell](https://byte.ski/notes/Fish-Shell) you probably will have something like this in the Terminal:

```
fish: Unknown command: nvm
```

Currently, I use [Fish Shell](https://byte.ski/notes/Fish-Shell). If you use something else you should check [detail information about troubleshooting on GitHub](https://github.com/nvm-sh/nvm#troubleshooting-on-macos).

Unfortunately, **nvm doesn't support Fish**. However, there is a solution called [fish-nvm](https://byte.ski/notes/fish-nvm). It is a wrapper for [Fish Shell](https://byte.ski/notes/Fish-Shell). You can install this by using [Fisher (Fish Shell Plugin Manager)](https://byte.ski/notes/Fisher-(Fish-Shell-Plugin-Manager)):

```
fisher install FabioAntunes/fish-nvm edc/bass
```

Now, if you type `nvm --version` you should see a version of [Node Version Manager](https://byte.ski/notes/Node-Version-Manager) that is installed on your local machine.


## Usage

### Node Installation

Now it's time to start using [Node Version Manager](https://byte.ski/notes/Node-Version-Manager) to install [Node](https://byte.ski/notes/Node) on the local machine.

To install **latest** version of Node you can use the command:

```
nvm install node
```

To see all versions of Node that are installed on your machine use the command:

```
nvm ls
```

It should print in the Terminal something like this:

```
->      v16.1.0
         system
default -> node (-> v16.1.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.1.0) (default)
stable -> 16.1 (-> v16.1.0) (default)

...
```

Pay attention to the symbol "->". It shows us which version of Node is current on the local machine. So, basically, when you type `node -v` you should see the same version as with "->" before (in that case this version is 16.1.0).

Now let's install another version of [Node](https://byte.ski/notes/Node). Let's say, I want to use some older version of Node. For example, 14 version. To install it use the command:

```
nvm install 14
```

It should install Node v.14.16.1. Let's look at the list of installed Node versions (***nvm ls***):

```
->     v14.16.1
        v16.1.0
         system
default -> node (-> v16.1.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.1.0) (default)
stable -> 16.1 (-> v16.1.0) (default)

...
```

Now we have two versions: 14.16.1 and 16.1.0. The current is 14 (the symbol "->" before).

To **switch to** version 16 use this command:

```
nvm use 16
```

We should see the answer of nvm:

```
Now using node v16.1.0 (npm v7.11.2)
```

And if we use the command ***nvm ls*** again we will see that the current version is 16.1.0.

### Uninstall Node

To uninstall **latest** version of [Node](https://byte.ski/notes/Node) use command:

```
nvm uninstall node
```

To uninstall **specific** version of Node (for example - 14) use command:

```
nvm uninstall 14
```

## Global npm packages

If you have some installed globally [npm](https://byte.ski/notes/npm) packages you should notice one thing. When you installed this npm package on one version of [Node](https://byte.ski/notes/Node) and then you switch to another version of Node, the installed npm package won't be available for you. It's because npm packages that were installed on different versions of Node located in different places.

An example. Now I am on version 16 of [Node](https://byte.ski/notes/Node). I want to install [Prettier](https://byte.ski/notes/Prettier) globally on my computer by [npm](https://byte.ski/notes/npm):

```
npm i -g prettier
```

And then we switch to version 14:

```
nvm use 14
prettier --version
```

You will see something like this:

```
prettier: command not found
```

Don't worry! If you want to use that package on version 14 you just need to install it again.

[npm](https://byte.ski/notes/npm) packages are located in specific folders for each version of [Node](https://byte.ski/notes/Node) that is installed by **nvm**.

Packages are located here (on macOS):

```
~/.nvm/versions/node/<version>/lib/node_modules
```


***Do you like the material? Please, [subscribe to my email newsletter](https://byte.ski/newsletter) to stay up to date.***

<a href="https://byte.ski/newsletter"><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fld1yqfgvgz2dgcpho0x.png" alt="subscribe" /></a>