How to Update and Manage Node.js version with n on CentOS 7.6
- 00:34 yum install -y gcc-c++ make
- 00:43 curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash -
- 00:53 yum install nodejs
- 01:02 node -v
- 01:08 npm -v
- 01:22 npm install -g n
- 01:23 n lts
- 01:37 node -v
- 01:45 n bin 10.15.3
- 01:54 vim /etc/profile
- 02:05 source /etc/profile
- 02:14 n 10.15.3
- 02:20 n prune
- 02:24 node -v
Installing, Updating and Managing Node.js with n
Pre-requisites:
Gcc-c++ and make
Download link :
curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash –
Installation procedure of node.js
Install the development tools that are required to install the node.js.
[root@linuxhelp ~]# yum install -y gcc-c++ make
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Package 1:make-3.82-23.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-36.el7_6.2 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-36.el7_6.2 for package: gcc-c++-4.8.5-36.el7_6.2.x86_64
--> Processing Dependency: libstdc++ = 4.8.5-36.el7_6.2 for package: gcc-c++-4.8.5-36.el7_6.2.x86_64
--> Processing Dependency: gcc = 4.8.5-36.el7_6.2 for package: gcc-c++-4.8.5-36.el7_6.2.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-c++-4.8.5-36.el7_6.2.x86_64
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-36.el7_6.2 will be installed
--> Processing Dependency: libgomp = 4.8.5-36.el7_6.2 for package: gcc-4.8.5-36.el7_6.2.x86_64
--> Processing Dependency: cpp = 4.8.5-36.el7_6.2 for package: gcc-4.8.5-36.el7_6.2.x86_64
--> Processing Dependency: libgcc >= 4.8.5-36.el7_6.2 for package: gcc-4.8.5-36.el7_6.2.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-36.el7_6.2.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
.
.
.
Dependency Installed:
cpp.x86_64 0:4.8.5-36.el7_6.2 gcc.x86_64 0:4.8.5-36.el7_6.2 glibc-devel.x86_64 0:2.17-260.el7_6.5
glibc-headers.x86_64 0:2.17-260.el7_6.5 kernel-headers.x86_64 0:3.10.0-957.12.2.el7 libmpc.x86_64 0:1.0.1-3.el7
libstdc++-devel.x86_64 0:4.8.5-36.el7_6.2
Dependency Updated:
glibc.x86_64 0:2.17-260.el7_6.5 glibc-common.x86_64 0:2.17-260.el7_6.5 libgcc.x86_64 0:4.8.5-36.el7_6.2
libgomp.x86_64 0:4.8.5-36.el7_6.2 libstdc++.x86_64 0:4.8.5-36.el7_6.2
Complete!
Add node.js yum repository and enable it in your system.
[root@linuxhelp ~]# curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash -
## Installing the NodeSource Node.js 8.x LTS Carbon repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.2IYZWXWcQM' 'https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.2IYZWXWcQM'
## Cleaning up...
+ rm -f '/tmp/tmp.2IYZWXWcQM'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `sudo yum install -y nodejs` to install Node.js 8.x LTS Carbon and npm.
## You may also need development tools to build native addons:
sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install yarn
After the addition of yum repository to the system, install node.js package where npm will aslo be installed with node.js.
[root@linuxhelp ~]# yum install nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
nodesource | 2.5 kB 00:00:00
nodesource/x86_64/primary_db | 46 kB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:8.16.0-1nodesource will be installed
--> Finished Dependency Resolution
.
.
.
Warning: RPMDB altered outside of yum.
Installing : 2:nodejs-8.16.0-1nodesource.x86_64 1/1
Verifying : 2:nodejs-8.16.0-1nodesource.x86_64 1/1
Installed:
nodejs.x86_64 2:8.16.0-1nodesource
Complete!
Check the version of node by running the following command
[root@linuxhelp ~]# node -v
v8.16.0
Check the version of npm by executing the following command.
[root@linuxhelp ~]# npm -v
6.4.1
You shall upgrade the node version by running the following command.
Install the node version manager n as follows
[root@linuxhelp ~]# npm install -g n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
+ n@4.1.0
added 1 package from 4 contributors in 0.758s
Upgrade the node version via n which installs a new version of a node under a folder managed by itself.
[root@linuxhelp ~]# n lts
install : node-v10.15.3
mkdir : /usr/local/n/versions/node/10.15.3
fetch : https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.gz
######################################################################## 100.0%
installed : v10.15.3
Check the version of node after the upgrading it.
[root@linuxhelp ~]# node -v
v8.16.0
Execute the command to know the system path
[root@linuxhelp ~]# n bin 10.15.3
/usr/local/n/versions/node/10.15.3/bin/node
Alter the system path in /etc/profile as follows:
[root@linuxhelp ~]# vim /etc/profile
# nodejs PATH
export NODE_HOME=/usr/local/n/versions/node/10.15.3/bin/node
export PATH=$NODE_HOME/bin:$PATH
Reset the profile by executing the following command
[root@linuxhelp ~]# source /etc/profile
Now,check the version of node.
[root@linuxhelp ~]# node -v
v10.15.3
Select the version of node that you want to keep by executing the following command
[root@linuxhelp ~]# n 10.15.3
Run the below command to remove the irrelevant packages in the version.
[root@linuxhelp ~]# n prune
With this, the method to install, upgrade and manage node.js using n on Centos 7.6 comes to end.
Comments ( 0 )
No comments available