Install Node.js through NVM and EPEL on CentOs/RHEL 7 Linux
Earlier we have done node.js installation through source package , you can find here that post from below link. Node.js Installation from Source . Here we are going to install node.js through two method first one is from EPEL repository and other from Node Version Manager ( NVM ) .
Method 1 : Install Node.js from EPEL Repository
I am going to configure node.js on CentOs 7 Server . first we need to configure EPEL on CentOs 7 from below link of article.
After installation run the below command for installation of node.js . I am assuming you have root previlage of server , otherwise if you have user sudo previlage , you need to use sudo before command.
# yum install nodejs
.... .... .... Installing : 1:v8-184.108.40.206-17.el7.x86_64 1/5 Installing : c-ares-1.10.0-3.el7.x86_64 2/5 Installing : http-parser-2.0-5.20121128gitcd01361.el7.x86_64 3/5 Installing : 1:libuv-0.10.34-2.el7.x86_64 4/5 Installing : nodejs-0.10.36-3.el7.x86_64 5/5 Verifying : 1:libuv-0.10.34-2.el7.x86_64 1/5 Verifying : http-parser-2.0-5.20121128gitcd01361.el7.x86_64 2/5 Verifying : nodejs-0.10.36-3.el7.x86_64 3/5 Verifying : c-ares-1.10.0-3.el7.x86_64 4/5 Verifying : 1:v8-220.127.116.11-17.el7.x86_64 5/5 Installed: nodejs.x86_64 0:0.10.36-3.el7 Dependency Installed: c-ares.x86_64 0:1.10.0-3.el7 http-parser.x86_64 0:2.0-5.20121128gitcd01361.el7 libuv.x86_64 1:0.10.34-2.el7 v8.x86_64 1:18.104.22.168-17.el7 .... .... ....
Here we are doing install npm to manage node packages.
# yum install npm
Method 2 : Install Nodejs from Node Version Manager ( NVM )
Second method we are using through nvm tool, that can manage node easily. To install nvm on centos 7 , you can download and execute script from git hub repository. Below are two command , which you can use to download and execute the script from curl and wget command.Follow below commands.
# curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash OR # wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
After run one of the command , the script output should be like below.
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7750 100 7750 0 0 32751 0 --:--:-- --:--:-- --:--:-- 32838 => Downloading nvm as script to '/root/.nvm' => Appending source string to /root/.bashrc => Close and reopen your terminal to start using nvm
From nvm list-remote command show which version of node its having in it. See the below output of below command.
# nvm list-remote
.... .... v4.0.0 v4.1.0 v4.1.1 v4.1.2 v4.2.0 v4.2.1 v4.2.2 v4.2.3 v4.2.4 v4.2.5 v4.2.6 v4.3.0 v5.0.0 v5.1.0 v5.1.1 v5.2.0 v5.3.0 v5.4.0 v5.4.1 v5.5.0 v5.6.0
Now you can select a version of node , which you require from list and install from below command,Here I am going to install latest stable version of node from nvm command.
# nvm install v5.6.0
If you have install earlier also node any version on server , you can see the version on server installed by list parameter and current use version of node.
# nvm list
Here I have fresh install stable version , so there is not any difference. Check below image.
If you got different version on server of node install , you can switch between them from below command.
To set any version which you want use below command .
# nvm use v5.6.0
For set default version , use alias parameter with nvm and node version.
To set this version as the default, type:
# nvm alias default [VERSSION]
Check Installed Node.js Version
Once the installation done , you can check through below command to check node.js version .
# node --version