CentOS 安装 nodejs

  1. nodejs下载网址:
    nodejs(LTS版本):Download | Node.js
    nodejs(当前最新版):Download | Node.js
    nodejs(全版本):Index of /dist/
    nodejs10(最新版):Index of /dist/latest-v10.x/
    nodejs11(最新版):Index of /dist/latest-v11.x/
    nodejs12(最新版):Index of /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. 修改为淘宝镜像:
    # http://npm.taobao.org 和 http://registry.npm.taobao.org 将在 2022.06.30 号正式下线和停止 DNS 解析
    # http://npm.taobao.org => http://npmmirror.com
    # http://registry.npm.taobao.org => http://registry.npmmirror.com
    npm config set registry=http://registry.npmmirror.com
    npm install -g cnpm --registry=http://registry.npmmirror.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐晓伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值