How to install Node.js in Ubuntu

To install Node.js in Ubuntu

Node.js is purely JavaScript-based platform used for building high-performance server-side applications in efficient manner. It allows the developers to use JavaScript on both the front-end and the back-end. Installation of Node.js in Ubuntu is explained in this article.

 

Installation of Node.js

First install the required packages for node.js by using the following command.

root@linuxhelp1:~# apt-get install build-essential checkinstall -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.1ubuntu2).
build-essential set to manually installed.
The following NEW packages will be installed:
  checkinstall
.
.
.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 checkinstall amd64 1.6.2-4ubuntu1 [121 kB]
Fetched 121 kB in 1s (68.4 kB/s)       
Selecting previously unselected package checkinstall.
(Reading database ... 208381 files and directories currently installed.)
Preparing to unpack .../checkinstall_1.6.2-4ubuntu1_amd64.deb ...
Unpacking checkinstall (1.6.2-4ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up checkinstall (1.6.2-4ubuntu1) ...


Next run the following command to install the libssl-dev package.

root@linuxhelp1:~# apt-get install libssl-dev -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libssl-doc zlib1g-dev
The following NEW packages will be installed:
  libssl-dev libssl-doc zlib1g-dev
0 upgraded, 3 newly installed, 0 to remove and 52 not upgraded.
Need to get 2,639 kB of archives.
After this operation, 10.8 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 zlib1g-dev amd64 1:1.2.8.dfsg-2ubuntu4 [168 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl-dev amd64 1.0.2g-1ubuntu4.2 [1,393 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl-doc all 1.0.2g-1ubuntu4.2 [1,078 kB]                    
Fetched 2,639 kB in 10s (255 kB/s)              
.
.
.
Preparing to unpack .../libssl-doc_1.0.2g-1ubuntu4.2_all.deb ...
Unpacking libssl-doc (1.0.2g-1ubuntu4.2) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4) ...
Setting up libssl-dev:amd64 (1.0.2g-1ubuntu4.2) ...
Setting up libssl-doc (1.0.2g-1ubuntu4.2) ...


Now its time to install and update the node version manager by using the curl command.

root@linuxhelp1:~#  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7766  100  7766    0     0   5901      0  0:00:01  0:00:01 --:--:--  5905
=> Downloading nvm as script to '/home/user1/.nvm'

=> Appending source string to /home/user1/.bashrc
=> Close and reopen your terminal to start using nvm


Here you have to close and reopen the terminal. Then run the below command to verify that nvm has been successfully installed or not.

root@linuxhelp1:~# command -v nvm
nvm


Run the following command to download, compile and install the latest version of Node.js

root@linuxhelp1:~# nvm install 5.0
Downloading https://nodejs.org/dist/v5.0.0/node-v5.0.0-linux-x64.tar.xz...
######################################################################## 100.0%
Now using node v5.0.0 (npm v3.3.6)
Creating default alias: default -> 5.0 (-> v5.0.0)

 

When the new shell is started, mention the nvm tool to use the respective node version.

root@linuxhelp1:~#  nvm use 5.0
Now using node v5.0.0 (npm v3.3.6)


Instead, use alias default command to set the default Node.js version for any new shell.

root@linuxhelp1:~#  nvm alias default node
default -> node (-> v5.0.0)

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Node.js
user image Author :  Jackson