CentOS7上安装Node.js

  • CentOS7上安装Node.js已关闭评论
  • 16 views
  • A+
所属分类:运维实战

项目需要装Node.js,所有就顺便记录一下

我们这里通过NodeSource安装,我这里安装的是8,直接开始吧.

 

下载并执行脚本

[root@k46gsv /]# curl -sL https://rpm.nodesource.com/setup_8.x | sudo 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.LZzXNGotJM' '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.LZzXNGotJM'
## Cleaning up...
+ rm -f '/tmp/tmp.LZzXNGotJM'
## 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

好了,已经提醒让安装nodejs

[root@k4622v /]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
ADDOPS-base | 2.9 kB 00:00:00 
base | 3.6 kB 00:00:00 
centosplus | 3.4 kB 00:00:00 
docker-ce-edge | 2.9 kB 00:00:00 
docker-ce-stable | 2.9 kB 00:00:00 
epel | 4.7 kB 00:00:00 
extras | 3.4 kB 00:00:00 
nodesource | 2.5 kB 00:00:00 
updates | 3.4 kB 00:00:00 
nodesource/x86_64/primary_db | 37 kB 00:00:01 
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:8.11.3-1nodesource will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package Arch Version Repository Size
===============================================================================================================================================
Installing:
 nodejs x86_64 2:8.11.3-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.3-1nodesource.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 34fa74dd: NOKEY
Public key for nodejs-8.11.3-1nodesource.x86_64.rpm is not installed
nodejs-8.11.3-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 <gpg-rpm@nodesource.com>"
 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.3-1nodesource.x86_64 1/1 
 Verifying : 2:nodejs-8.11.3-1nodesource.x86_64 1/1

Installed:
 nodejs.x86_64 2:8.11.3-1nodesource

Complete!

好了,这就安装完了,我们来测试一下:

node版本:

[root@k4622v /]# node --version
v8.11.3

npm版本:

[root@k4622v /]# npm --version
5.6.0

另外就是上面安装的时候提醒需要安装开发工具库,我们这里也安装一下:

yum install gcc-c++ make -y

好了,到此结束

  • 我的微信
  • 微信扫一扫
  • weinxin
  • 微信公众号
  • 微信公众号扫一扫
  • weinxin
avatar