CentOS7 下 yum安装新版nodejs

centos7 前端 · ez · 于 4年前 发布 · 3965 次阅读

官网安装说明:https://github.com/nodesource/distributions/blob/master/README.md

系统的yum源安装nodejs版本太低。

如果你的系统版本比较低,gcc库版本低,编译安装的时候有可能不成功,所以准备工作。

sudo yum install gcc-c++ make

下面是yum安装的步骤:

第一步,设置RPM源

curl -sL https://rpm.nodesource.com/setup_12.x | bash -

详细参考:https://github.com/nodesource/distributions#enterprise-linux-based-distributions

## Installing the NodeSource Node.js 12.x 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_12.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.R9LRnQvO7i' 'https://rpm.nodesource.com/pub_12.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.R9LRnQvO7i'

## Cleaning up...

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

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `sudo yum install -y nodejs` to install Node.js 12.x 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

sudo yum install -y nodejs

如果以上步骤不能安装 最新版 node,执行以下命令后再重新执行安装命令:

sudo yum clean all

清理源仓库设置

如果存在多个 nodesoucre,执行以下命令删除,从第一步重新操作

sudo rm -fv /etc/yum.repos.d/nodesource*

本文由 ez 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。

共收到 0 条回复
没有找到数据。
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册