zoukankan      html  css  js  c++  java
  • linux下升级npm以及node

    npm升级

    废话不多说,直接讲步骤。先从容易的开始,升级npm。

    npm这款包管理工具虽然一直被人们诟病,很多人都推荐使用yarn,但其使用人数还是不见减少,况且npm都是随node同时安装好的,一时让我抛弃它,还是有点难做到。

    npm i -g npm
    • 1

    是的,你没看错。升级npm只需要像安装其它包一样install一下就行,windows和linux下都可以通过此方式进行升级,你还能指定npm的版本。

    npm i -g npm@5.0.0
    • 1

    node升级

    node升级相对于npm来说就复杂一点了。

    1、首先通过npm安装node的版本管理工具“n“,不用惊讶,名字就是这么简单,就叫n。据了解,n是node下的一个模块,作者是Express框架的开发者。

    npm i -g n
    • 1

    2、检查n模块

    先查看系统node的安装路径,n模块的默认路径为 ‘/usr/local’。

    $ which node
    
    /data/home/server/nodejs/bin/node   #举个例子
    • 1
    • 2
    • 3

    如果路径与n模块的默认路径相同可以跳过3步骤。

    3、通过N_PREFIX变量来修改 n 的默认node安装路径。

    (1) 编辑环境配置文件

    vim ~/.bash_profile   
    • 1

    (2) 将下面两行代码插入到文件末尾

    export N_PREFIX=/data/home/server/nodejs #node实际安装位置
    export PATH=$N_PREFIX/bin:$PATH
    • 1
    • 2

    (3) :wq保存退出;

    执行source使修改生效。

    $ source ~/.bash_profile
    • 1

    (4) 确认一下环境变量是否生效。

    echo $N_PREFIX
    /data/home/server/nodejs
    • 1
    • 2

    4、n模块常用命令

    Commands:
    
      n                              Output versions installed
      n latest                       Install or activate the latest node release
      n -a x86 latest                As above but force 32 bit architecture
      n stable                       Install or activate the latest stable node release
      n lts                          Install or activate the latest LTS node release
      n <version>                    Install node <version>
      n use <version> [args ...]     Execute node <version> with [args ...]
      n bin <version>                Output bin path for <version>
      n rm <version ...>             Remove the given version(s)
      n prune                        Remove all versions except the current version
      n --latest                     Output the latest node version available
      n --stable                     Output the latest stable node version available
      n --lts                        Output the latest LTS node version available
      n ls                           Output the versions of node available
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    (1) 安装node最新版本

    n latest
    • 1

    (2) 安装稳定版

    n stable
    • 1

    (3) 安装指定版本

    n v7.10.0
    • 1

    (4) 查看已安装版本

    n
    • 1

    (5) 删除指定版本

    n rm 6.4.0
    • 1

    最后,linux下还有一款基于shell的node管理工具nvm,有兴趣的同学也可以自己尝试下。

  • 相关阅读:
    JS高级——eval
    JS高级——Object.prototype成员
    JS高级——原型链
    JS高级——逻辑中断
    移动web——bootstrap媒体对象
    移动web——bootstrap如何修改原组件
    移动web——bootstrap响应式轮播图
    Leetcode题解
    位运算实现四则运算(C++实现)
    扫码登陆原理
  • 原文地址:https://www.cnblogs.com/weiguoaa/p/9048155.html
Copyright © 2011-2022 走看看