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 8 Server. first, we need to configure EPEL on CentOs 6 / 7 / 8 Version from the below link of the 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
Running transaction Running scriptlet: npm-1:6.13.4-18.104.22.168.1.module_el8.1.0+277+2bccb1a9.x86_64 Preparing : Installing : npm-1:6.13.4-22.214.171.124.1.module_el8.1.0+277+2bccb1a9.x86_64 Installing : nodejs-1:10.19.0-1.module_el8.1.0+277+2bccb1a9.x86_64 Running scriptlet: nodejs-1:10.19.0-1.module_el8.1.0+277+2bccb1a9.x86_64 Verifying : nodejs-1:10.19.0-1.module_el8.1.0+277+2bccb1a9.x86_64 Verifying : npm-1:6.13.4-126.96.36.199.1.module_el8.1.0+277+2bccb1a9.x86_64 Installed: nodejs-1:10.19.0-1.module_el8.1.0+277+2bccb1a9.x86_64
Check Version Installed
[[email protected] ~]# node --version v10.19.0
Method 2 : Install Nodejs from Node Version Manager ( NVM )
The second method we are using through nvm tool, that can manage node easily. To install nvm on centos 7, you can download and execute the script from the git hub repository. Below are two commands, which you can use to download and execute the script from curl and wget command. Follow the below commands.
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/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
.... .... v12.12.0 v12.13.0 (LTS: Erbium) v12.13.1 (LTS: Erbium) v12.14.0 (LTS: Erbium) v12.14.1 (LTS: Erbium) v12.15.0 (LTS: Erbium) v12.16.0 (LTS: Erbium) v12.16.1 (LTS: Erbium) v12.16.2 (Latest LTS: Erbium) v13.0.0 v13.0.1 v13.1.0 v13.2.0 v13.3.0 v13.4.0 v13.5.0 v13.6.0 v13.7.0 v13.8.0 v13.9.0 v13.10.0 v13.10.1 v13.11.0 v13.12.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 v13.12.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 v13.12.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 is done, you can check through the below command to check the node.js version.
# node --version
I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks!