Table of Contents

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 using nvm

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

Installing nvm is also easy. Before we install nvm, make sure to remove the older version of nvm first.

rm -rf ~/.nvm

To make sure, you install the latest version go to following link and find out the latest version to install.

github.com/nvm-sh/nvm

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash

Check if you have following in your ~/.bashrc

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

Let us install nodejs now using nvm.

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

Lets verify now.

node --version
v16.18.1

How about npm?

npm --version
6.13.6

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

nvm --version
0.39.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.

Related Posts

1