CentOS 安装 nodejs

  1. nodejs下载网址:
    nodejs(LTS版本):https://nodejs.org/en/download/
    nodejs(当前最新版):https://nodejs.org/en/download/current/
    nodejs(全版本):https://nodejs.org/dist/
    nodejs10(最新版):https://nodejs.org/dist/latest-v10.x/
    nodejs11(最新版):https://nodejs.org/dist/latest-v11.x/
    nodejs12(最新版):https://nodejs.org/dist/latest-v12.x/
     
  2. 本次使用版本:node-v12.7.0-linux-x64.tar.gz
     
  3. 解压:
    tar -zxvf node-v12.7.0-linux-x64.tar.gz
  4. 将解压后的文件夹移动到 /usr/local/lib64 目录中:
    mv node-v12.7.0-linux-x64 /usr/local/lib64/node-v12.7.0-linux-x64
  5. 配置环境变量:
    1. 打开配置文件:
      vim /etc/profile
    2. 添加配置:
      NODE_HOME=/usr/local/lib64/node-v12.7.0-linux-x64
      NODE_GLOBAL=/usr/local/lib64/node-v12.7.0-linux-x64/node_global
      export PATH=$NODE_HOME/bin:$NODE_GLOBAL/bin:$PATH
      
    3. 刷新配置文件:
      source /etc/profile
  6. 测试是否配置成功:
    [root@desktop ~]# node -v
    v12.7.0
    
    [root@desktop ~]# npm version
    {
      npm: '6.10.0',
      ares: '1.15.0',
      brotli: '1.0.7',
      cldr: '35.1',
      http_parser: '2.8.0',
      icu: '64.2',
      llhttp: '1.1.4',
      modules: '72',
      napi: '4',
      nghttp2: '1.39.1',
      node: '12.7.0',
      openssl: '1.1.1c',
      tz: '2019a',
      unicode: '12.1',
      uv: '1.30.1',
      v8: '7.5.288.22-node.16',
      zlib: '1.2.11'
    }
    
    [root@desktop ~]# npx -v
    6.10.0
    
  7. 配置目录:
    npm config set prefix /usr/local/lib64/node-v12.7.0-linux-x64/node_global
    npm config set cache /usr/local/lib64/node-v12.7.0-linux-x64/node_cache
    
  8. 安装 vue/cli 测试:
    [root@desktop ~]# npm install -g @vue/cli
    /usr/local/lib64/node-v12.7.0-linux-x64/bin/vue -> /usr/local/lib64/node-v12.7.0-linux-x64/lib/node_modules/@vue/cli/bin/vue.js
    
    > core-js@3.1.4 postinstall /usr/local/lib64/node-v12.7.0-linux-x64/lib/node_modules/@vue/cli/node_modules/core-js
    > node scripts/postinstall || echo "ignore"
    
    Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
    
    The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
    > https://opencollective.com/core-js 
    > https://www.patreon.com/zloirock 
    
    Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
    
    
    > core-js-pure@3.1.4 postinstall /usr/local/lib64/node-v12.7.0-linux-x64/lib/node_modules/@vue/cli/node_modules/core-js-pure
    > node scripts/postinstall || echo "ignore"
    
    Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
    
    The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
    > https://opencollective.com/core-js 
    > https://www.patreon.com/zloirock 
    
    Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
    
    
    > protobufjs@6.8.8 postinstall /usr/local/lib64/node-v12.7.0-linux-x64/lib/node_modules/@vue/cli/node_modules/protobufjs
    > node scripts/postinstall
    
    
    > nodemon@1.19.1 postinstall /usr/local/lib64/node-v12.7.0-linux-x64/lib/node_modules/@vue/cli/node_modules/nodemon
    > node bin/postinstall || exit 0
    
    Love nodemon? You can now support the project via the open collective:
     > https://opencollective.com/nodemon/donate
    
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/@vue/cli/node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    
    + @vue/cli@3.9.3
    added 842 packages from 545 contributors in 447.525s
    
  9. 创建 sudo 链接:
    sudo ln -s /usr/local/lib64/node-v12.7.0-linux-x64/bin/node /usr/bin/node
    sudo ln -s /usr/local/lib64/node-v12.7.0-linux-x64/bin/npm /usr/bin/npm
    sudo ln -s /usr/local/lib64/node-v12.7.0-linux-x64/bin/npx /usr/bin/npx
  10. 查看配置:
    npm config ls -l
  11. 查看镜像:
    [root@desktop ~]# npm config get registry
    https://registry.npmjs.org/
    
  12. 修改为淘宝镜像:
    npm config set registry=https://registry.npm.taobao.org
    npm install -g cnpm --registry=https://registry.npm.taobao.org
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值