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
  1. 官网获取LTS版linux64的node10.x下载地址,或淘宝镜像,自己选一个v10的,建议去淘宝的,比较快
  2. 下载
    cd /opt/
    wget https://npm.taobao.org/mirrors/node/latest-v10.x/node-v10.22.0-linux-x64.tar.xz

     

  3. 解压
    tar xvJf node-v10.22.0-linux-x64.tar.xz
    mv node-v10.22.0-linux-x64 /usr/local/nodejs

     

  4. 配置环境变量
    vim /etc/profile

    末尾添加

    # nodejs
    export NODE_HOME=/usr/local/nodejs
    export PATH=$PATH:${NODE_HOME}/bin

     

  5. 生效

    source /etc/profile

     

  6. 检查是否安装成功
    node -v
    npm -v

     

  7. 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

     

  8. 更新
    npm install -g npm

     

  9. 解决npm权限问题
    npm config -g set unsafe-perm

     

  10. 解决node-sass 安装失败
    # 设置全局镜像源 之后再涉及到 node-sass 的安装时就会从淘宝镜像下载。
    npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/

     

 

posted @ 2020-07-28 14:33  soldier_cnblogs  阅读(441)  评论(0编辑  收藏  举报