Skip to content

可能是目前最详细简明的CentOS7安装与管理教程(9):Node #11

@gaoac

Description

@gaoac
nvm

为了方便管理 node,我们使用 NVM(node 版本管理器)
安装(先确保安装过 curl /wget 工具,没有就安装下):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

安装完后,重新打开终端,查看安装情况:
nvm --version

[root@localhost ~]# nvm --version
0.33.8

nvm 常用命令:

nvm install ## 安装指定版本,可模糊安装,如:安装 v8.9.4,既可 nvm install v8.9.4,又可 nvm install 8.9.4

nvm uninstall ## 删除已安装的指定版本,语法与 install 类似

nvm use ## 切换使用指定的版本 node

nvm list ## 列出所有安装的版本

nvm list-remote ## 列出所有远程服务器的版本(官方 node version list)

nvm current ## 显示当前的版本

nvm alias ## 给不同的版本号添加别名

nvm unalias ## 删除已定义的别名

nvm reinstall-packages ## 在当前版本 node 环境下,重新全局安装指定版本号的 npm 包

我们安装当前 LTS(长期稳定版)v8.9.4 以及最新版
nvm install 8.9.4
nvm install 9.6.0

查看已安装版本:

[root@localhost ~]# nvm list
         v8.9.4 *
->       v9.6.0 *
default -> 8.9.4 (-> v8.9.4 *)
node -> stable (-> v9.6.0 *) (default)
stable -> 9.6 (-> v9.6.0 *) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.9.4 *)
lts/argon -> v4.8.7 (-> N/A)
lts/boron -> v6.13.0 (-> N/A)
lts/carbon -> v8.9.4 *

然后使用 8.9.4:
nvm use 8.9.4

[root@localhost ~]# nvm use 8.9.4
Now using node v8.9.4 (npm v5.6.0)

查看当前版本:
nvm current

[root@localhost ~]# nvm current
v8.9.4
nrm

接下来我们安装 nrm(管理 npm 源切换的利器)

安装:
npm install -g nrm

nrm 常用命令:
>

nrm ls : 显示所有 registry

nrm current : 显示当前 registry

nrm use xxx : 使用 xxx registry

nrm ls

[root@localhost ~]# nrm ls

* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/

nrm use taobao
再次查看,npm 源已切换到 taobao:

[root@localhost ~]# nrm ls

  npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/

淘宝 NPM 镜像
是一个完整 npmjs.org 镜像,你可以用此代替官方版本(只读),同步频率目前为 10 分钟 一次以保证尽量与官方服务同步。

接下来,就可以随意使用 npm 安装 node 模块包了。
如:npm install -g npm-check yarn serve pm2 typescript

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions