Centos使用yum快速安装Node和NPM

第一步、配置安装版本(这里安装 8.x)

curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -

控制台输出

[root@iZbp109iqt20o2h63tpcuvZ dev]# curl --silent --location https://rpm.nodesource.com/setup_8.x | 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.tWMwjlkMPm' '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.tWMwjlkMPm'

## Cleaning up...

+ rm -f '/tmp/tmp.tWMwjlkMPm'

## 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

第二步,开始安装

yum install -y nodejs

控制台输出

[root@iZbp109iqt20o2h63tpcuvZ dev]# yum install -y nodejs
Loaded plugins: fastestmirror
nodesource                                                                                                                       | 2.5 kB  00:00:00     
nodesource/x86_64/primary_db                                                                                                     |  35 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * remi-safe: mirrors.tuna.tsinghua.edu.cn
 * webtatic: uk.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:8.11.2-1nodesource will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================
 Package                        Arch                           Version                                         Repository                          Size
========================================================================================================================================================
Installing:
 nodejs                         x86_64                         2:8.11.2-1nodesource                            nodesource                          17 M

Transaction Summary
========================================================================================================================================================
Install  1 Package

Total download size: 17 M
Installed size: 51 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/nodesource/packages/nodejs-8.11.2-1nodesource.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 34fa74dd: NOKEY00 ETA 
Public key for nodejs-8.11.2-1nodesource.x86_64.rpm is not installed
nodejs-8.11.2-1nodesource.x86_64.rpm                                                                                             |  17 MB  00:00:02     
Retrieving key from file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
Importing GPG key 0x34FA74DD:
 Userid     : "NodeSource "
 Fingerprint: 2e55 207a 95d9 944b 0cc9 3261 5ddb e8d4 34fa 74dd
 Package    : nodesource-release-el7-1.noarch (installed)
 From       : /etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
	Installing : 2:nodejs-8.11.2-1nodesource.x86_64                                                                                                   1/1 
	Verifying  : 2:nodejs-8.11.2-1nodesource.x86_64                                                                                                   1/1 

Installed:
	nodejs.x86_64 2:8.11.2-1nodesource                                                                                                                    

Complete!

安装完毕,查看Node和NPM版本号

[root@iZbp109iqt20o2h63tpcuvZ dev]# node -v
v8.11.2
[root@iZbp109iqt20o2h63tpcuvZ dev]# npm -v
5.6.0

(完)

你可能感兴趣的:(Linux)