Ruan Bekker's Blog

From a Curious mind to Posts on Github

Install Nodejs on Linux Using NVM

In this post we will install Nodejs using Node Version Manager (nvm), which allows you to install and use different versions of node via the command line.

For more information on NVM, checkout their github repository

Install

I will be using a debian based linux distribution, so I first will be updating my package manager’s indexes:

1
$ apt update

Then I will install NVM using the instructions from their repository (always ensure that you are aware what you are installing when you curl, pipe, bash):

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

Verify

You can now log out and log back in for your path to be updated, or you can follow the instructions on your terminal to source your session so that your path to nvm is updated:

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

Then you can verify if nvm is in your path:

1
2
$ command -v nvm
nvm

Installing a Node Version

Before we install a specific version of nodejs, let’s first look at the LTS versions from the Fermium release:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ nvm ls-remote --lts=fermium
       v14.15.0   (LTS: Fermium)
       v14.15.1   (LTS: Fermium)
       v14.15.2   (LTS: Fermium)
       v14.15.3   (LTS: Fermium)
       v14.15.4   (LTS: Fermium)
       v14.15.5   (LTS: Fermium)
       v14.16.0   (LTS: Fermium)
       v14.16.1   (LTS: Fermium)
       v14.17.0   (LTS: Fermium)
       v14.17.1   (LTS: Fermium)
       v14.17.2   (LTS: Fermium)
       v14.17.3   (LTS: Fermium)
       v14.17.4   (LTS: Fermium)
       v14.17.5   (LTS: Fermium)
       v14.17.6   (LTS: Fermium)
       v14.18.0   (Latest LTS: Fermium)

So I want to install v14.8.0:

1
$ nvm install 14.8.0

I also would like to make it my default version of node:

1
2
$ nvm alias default node
default -> node (-> v14.8.0)

Verify Installation

Now we can verify if npm is installed:

1
2
$ npm -v
6.14.7

as well as node:

1
2
$ node -v
v14.8.0

Thank You

Thanks for reading, if you like my content, check out my website or follow me at @ruanbekker on Twitter.

-->

Comments