Nodejs is considered a well-known programming language. And many developers use this language for developing their projects for its benefits. Nodejs, most of the time, are not installed on centos distributions, or an old version is installed, which is not enough or cannot satisfy the requirements of a project.
In this tutorial, we will show how to install the latest version of Nodejs in two ways that can satisfy any circumstances.
as the stable and long term support of Nodejs is 12 version, in this article, we will support version 12 for both methods.
1.Installing from repository :
1-1. Download the repository from Nodejs website with curl command and install it.
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -
1-2. Install Nodejs package with below command.
sudo yum install nodejs
1-3. Verify and check is Nodejs installed or not.
please note that, when you install Nodejs, a dependency package ( npm ) which is package manager of Nodejs will be installed. run below command to see the result.
# node --version
v12.22.0
# npm --version
6.14.11
2.Installing from source code and binary :
Node website allows to anyone to have an option for compling or using compiled version of Nodejs. when a person wants to install Nodejs and there is not internet access especially in some local datacenters around the world. Nodejs can be downloaded and installed on specific user and locally not globally on OS.
2-1. Download and unzip with related tools. In this case we use tar command.
cd ~; wget -c https://nodejs.org/dist/latest-v12.x/node-v12.22.0-linux-x64.tar.gz
tar -zxf node-v12.22.0-linux-x64.tar.gz
2-2. Run below commands to add node to your local profile.
mv node-v12.22.0-linux-x64 node
echo "PATH=$PATH:$HOME/node/bin" >> .bash_profile
echo "export PATH" >> .bash_profile
2-3. Verify Nodejs and npm version :
$ node -v
v12.22.0
$ npm -v
6.14.11
As you can node is installed and can be used anytime. The second method is globally on Linux distro and not dedicated to any distributions.
Regards,
Farhad.