在Centos6或7上安装nodejs最简单的方式还是yum,但是默认epel源中nodejs版本过旧,本文介绍下新版nodejs安装方法。
方法来自:https://github.com/nodesource/distributions
1、安装NodeJS10.x
1 2 |
curl -sL https://rpm.nodesource.com/setup_10.x | bash - yum install nodejs |
2、查看版本
1 2 |
node -v v10.16.3 |
1 2 |
npm -v 6.9.0 |
3、更换镜像(可选)
更换淘宝镜像
1 |
npm config set registry https://registry.npm.taobao.org |
查看是否更换成功
1 |
npm config get registry |
更换回官方源
1 |
npm config set registry https://registry.npmjs.org |
附:安装其他版本的NodeJS
NodeJS 12.x
1 2 |
curl -sL https://rpm.nodesource.com/setup_12.x | bash - yum install nodejs |
NodeJS 11.x
1 2 |
curl -sL https://rpm.nodesource.com/setup_11.x | bash - yum install nodejs |
NodeJS 8.x
1 2 |
curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install nodejs |
NodeJS 8.17.0二进制方式安装
下载nodejs二进制版
https://nodejs.org/dist/v8.17.0/node-v8.17.0-linux-x64.tar.xz
解压缩配置环境变量即可
1 2 3 4 |
vi /etc/profile export NODE_HOME=/node-v8.17.0-linux-x64 export PATH=$NODE_HOME/bin:$PATH export NODE_PATH=$NODE_HOME/lib/node_modules |
附国内镜像源
淘宝镜像源
1 |
npm config set registry https://registry.npmmirror.com |
腾讯云镜像源
1 |
npm config set registry http://mirrors.cloud.tencent.com/npm/ |
华为云镜像源
1 |
npm config set registry https://mirrors.huaweicloud.com/repository/npm |
镜像源验证
1 |
npm config get registry |
删除镜像源
1 |
npm config rm registry |
原文链接:Centos6/7安装node.js,转载请注明来源!