CentOS7安装配置Nodejs
为防止gulp与node版本冲突,本文只下载node 10.x版本,否则到时候报错
ReferenceError: primordials is not defined at fs.js:36:5 at req_ (/var/lib/jenkins/workspace/diyuan-farm-vue/node_modules/natives/index.js:143:24) at Object.req [as require] (/var/lib/jenkins/workspace/diyuan-farm-vue/node_modules/natives/index.js:55:10) at Object.<anonymous> (/var/lib/jenkins/workspace/diyuan-farm-vue/node_modules/graceful-fs/fs.js:1:37) at Module._compile (internal/modules/cjs/loader.js:1137:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Module.require (internal/modules/cjs/loader.js:1025:19) at require (internal/modules/cjs/helpers.js:72:18) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! diyuan-farm-vue@1.0.0 build: `gulp` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the diyuan-farm-vue@1.0.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
本人是报错后才修改的,原本使用的是node
- 官网获取LTS版linux64的node10.x下载地址,或淘宝镜像,自己选一个v10的,建议去淘宝的,比较快
- 下载
cd /opt/ wget https://npm.taobao.org/mirrors/node/latest-v10.x/node-v10.22.0-linux-x64.tar.xz
- 解压
tar xvJf node-v10.22.0-linux-x64.tar.xz
mv node-v10.22.0-linux-x64 /usr/local/nodejs
- 配置环境变量
vim /etc/profile
末尾添加
# nodejs export NODE_HOME=/usr/local/nodejs export PATH=$PATH:${NODE_HOME}/bin
-
生效
source /etc/profile
- 检查是否安装成功
node -v npm -v
- npm换源
npm config set registry https://registry.npm.taobao.org #如果只是临时改变源,可以这样 npm --registry=https://registry.npm.taobao.org
淘宝源有时候会有问题,还是需要切换到官方源
npm config set registry http://registry.npmjs.org
- 更新
npm install -g npm
- 解决npm权限问题
npm config -g set unsafe-perm
- 解决node-sass 安装失败
# 设置全局镜像源 之后再涉及到 node-sass 的安装时就会从淘宝镜像下载。 npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/