How To Install or Update Node by Using nvm (Node Version Manager)
Photo by Lucky

How To Install or Update Node by Using nvm (Node Version Manager)


Intro

There are few ways to install Node on your local machine. The most popular way is to install it following official website instructions. 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).

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.

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

1
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:

1
nvm --version

You should see the current version of Node Version Manager that is installed on your local machine.

Shell Troubleshooting

If you use some shell as Z shell or Fish Shell you probably will have something like this in the Terminal:

1
fish: Unknown command: nvm

Currently, I use Fish Shell. If you use something else you should check detail information about troubleshooting on GitHub.

Unfortunately, nvm doesn’t support Fish. However, there is a solution called fish-nvm. It is a wrapper for Fish Shell. You can install this by using Fisher (Fish Shell Plugin Manager):

1
fisher install FabioAntunes/fish-nvm edc/bass

Now, if you type nvm --version you should see a version of Node Version Manager that is installed on your local machine.

Usage

Node Installation

Now it’s time to start using Node Version Manager to install Node on the local machine.


Master Go (Golang) with Weekly Tips, Tutorials and Exclusive Courses

Keep your Go (Golang) skills sharp and up-to-date with my exclusive newsletter. Subscribe now to get:

  • Weekly tips and tricks
  • In-depth tutorials
  • Exclusive courses
  • Industry insights and best practices

Join growing community of Go (Golang) developers and take your skills to the next level.

Latest Issues
    Marketing permission (GDPR) I give my consent to Max Kovalevsky to be in touch with me via email using the information I have provided in this form for the purpose of news, updates and marketing.
    We won't send you spam. Unsubscribe at any time.

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

    1
    
    nvm install node
    

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

    1
    
    nvm ls
    

    It should print in the Terminal something like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    ->      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. Let’s say, I want to use some older version of Node. For example, 14 version. To install it use the command:

    1
    
    nvm install 14
    

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

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    ->     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:

    1
    
    nvm use 16
    

    We should see the answer of nvm:

    1
    
    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 use command:

    1
    
    nvm uninstall node
    

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

    1
    
    nvm uninstall 14
    

    Global npm packages

    If you have some installed globally npm packages you should notice one thing. When you installed this npm package on one version of 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. I want to install Prettier globally on my computer by npm:

    1
    
    npm i -g prettier
    

    And then we switch to version 14:

    1
    2
    
    nvm use 14
    prettier --version
    

    You will see something like this:

    1
    
    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 packages are located in specific folders for each version of Node that is installed by nvm.

    Packages are located here (on macOS):

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