在centos上使用EPEL安装nodejs

286 阅读1分钟

0、了解 linux 版本

uname -a  命令查看到我的Linux系统位数是64位(备注:x86_64表示64位系统, i686 i386表示32位系统)

1、下载 EPEL (第一步可能没用~,直接看第二步)

找的方法

Download the latest epel-release rpm from
http://dl.fedoraproject.org/pub/epel/7/,下载rpm文件

dl.fedoraproject.org/pub/epel/7/…

sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm

2、安装完成,执行

//https://github.com/nodesource/distributions

//更新node.js各版本yum源
//Node.js v8.x安装命令
#curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -

//Node.js v7.x安装命令
#curl --silent --location https://rpm.nodesource.com/setup_7.x | bash -

//Node.js v6.x安装命令
#curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -

//Node.js v5.x安装命令
#curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

//yum安装node.js
yum install -y nodejs

3、检查 Node.js 和 npm 版本

node -v
npm -v

我在 yum 安装的时候运行了第一步 EPEL,导致 epel 源出错或版本不一致,最后删除了/etc/yum.repos.d/的相关 node 源,yum clean all --> yum makecache ,后才可以正常安装 nodejs

切换源

npm config set registry https://registry.npm.taobao.org
npm config set registry https://registry.npmmirror.com

其它资源更改
在更新 node-[sass]中,有时候也会出现资源下载不了的问题,通常是 git 上的资源下载不了,这时候,可以更改 node-sass 的资源路径为淘宝的

npm config set sass_binary_site=https://npmmirror.com/mirrors/node-s

ass/

**phantomjs 的源 **

npm config set phantomjs_cdnurl=https://nnpmmirror.com/mirrors/phantomjs/

**electron 源 **

npm config set electron_mirror=https://npmmirror.com/mirrors/electron/

设置全局安装目录
npm config set cache "D:\nodejs\node_cache"
npm config set prefix "D:\nodejs\node_global"

然后就可以愉快的使用 cnpm 安装工具了

常用命令集合
1. node -v #查看安装版本

2. npm -v #查看npm安装版本

3. npm config ls -l #查看配置项