Install NVM (Node Version Manager) for Node.js on Ubuntu 18.04

Posted by Stefan Kecskes on Thursday, February 7, 2019

Managing Node.js version through NVM

Node.js is javascript runtime. I am not going to explain why and how it can be used, you can check yourself on node.js website. But the fact is that Node.js comes in different versions and if you used it in the past, you might be familiar that sometimes you just need other version, sometimes newer version, other times older version. There is a easy way to manage those versions with a single command and that’s what I want to introduce you to today. the tool is called NVM, which is shortcut to Node Version Manager. I will show you how to install the latest version on Ubuntu 18.04 although the same steps should work on any unix like system.


Installing latest NVM

First we need to check what is the latest version of NVM from GitHub. We can go directly to [](nvm latest releases on github) and make note of latest release. At the time of writing it was v0.34.0, so that is version of NVM we are going to install.

First we will update packages and install build-essential, which should be already installed, but in case it isn’t

    apt update
    apt install build-essential libssl-dev

Next we will download the nvm using curl and execute the installation script:

    curl | bash

After this step we need a fresh terminal, so please close and reopen terminal to start using nvm. We can now validate that the nvm is installed correctly with command

    stefan@ubuntu:~/$ nvm --version

which in my case outputs 0.34.0. Great. Now we can start to use it. I suggest, let’s check all LTS (long term support) versions of nodejs and install the latest one

    nvm ls-remote --lts
    nvm install 10.15.1

And that’s it. As you can see we just installed latest version of Node.js and npm into our system. You can easily validate with commands

    stefan@ubuntu:~/$ npm -v
    stefan@ubuntu:~/$ node -v

Once you install more versions you don’t have to uninstall them, just switch the version using nvm use 10.15.1 which will change version until you close terminal. If you want permanently switch to other version of nvm then just run nvm alias default 10.15.1.

Thank you for your attention. That’s all for today.