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

published by on

Node.js

Node.js is javascript runtime. I am not going to explain why and how it can be used, you can check yourself on https://nodejs.org/en/about/. But the fact is that Node.js comes in different versions and if you used it in 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 shwould 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 https://github.com/creationix/nvm/releases 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 install script:


    curl https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | 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


    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 commnads


    stefan@ubuntu:~/$ npm -v
    6.4.1
    stefan@ubuntu:~/$ node -v
    v10.15.1

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 attention. That's all for today.

Tags: nvm npm nodejs