How To Install and Updgrade Nodejs On Linux

Updgrading nodejs involves following two steps. If you want to install it first time, skip to next section.

  • Remove existing nodejs
  • Install latest nodejs

Assuming you have nodejs already installed. Lets check ist the version of nodejs installed on the system.

node --version
v6.17.1

Lets check the version of latest available on following nodejs site.

github.com/nodesource/distributions

As of writing this post. Node.js v13.x is available.

Uninstall nodejs

Lets first uninstall the existing nodejs version which is easy using yum remove command.

yum -y remove nodejs

Lets check if the nodejs is removed or not.

nodejs --version
bash: nodejs: command not found

Ok if you see above error that means, nodejs is uninstalled.

Lets now install the latest version Node.js v13.x

curl -sL https://rpm.nodesource.com/setup_13.x | sudo bash -
yum -y install nodejs

You should see following output...

Installed: nodejs.x86_64 2:13.7.0-1nodesource

Complete!

node --version
v13.7.0

As we see above nodejs version 13.7.0 is installed. When we install nodejs nodejs package manager is automatically installed by yum. Lets verify that.

npm --version
6.13.6

There you go we got npm succesfully installed too.

Install nodejs latest version

nodejs can be installed using nvm too. nvm is a nodejs version manager.

Installing nvm is also easy. To make sure, you install the latest version go to following link and find out the latest verion to install.

github.com/nvm-sh/nvm

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

Add following to your bashrc file.

echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
source ~/.bashrc

Lets install nodejs now using nvm.

nvm install node
Downloading and installing node v13.7.0...
Downloading https://nodejs.org/dist/v13.7.0/node-v13.7.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v13.7.0 (npm v6.13.6)
Creating default alias: default -> node (-> v13.7.0)

Lets verify now.

node --version
v13.7.0

How about npm?

npm --version
6.13.6

Now you should have nvm installed in your environment. Lets verfiy it with following command.

nvm --version
0.35.2

Wrap Up!

In this tutorial, we have gone through the steps of how we can uninstall and then install the latest version of nodejs using two methods. Hope you would find above post useful.