1.安装nvm
nvm是一个非常不错的node版本管理器,类似于ruby的rvm
github地址为https://github.com/creationix/nvm
1.首先下载nvm,这里我们需要使用Git,确保提前安装好了git:
sudo apt-get install git
2.然后执行以下命令从git载入nvm:
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
3.下载之后,进入目录执行nvm安装命令
./install.sh
4.安装之后输入nvm还是提示没有这时候需要执行以下命令或者关闭终端重新开启
source ./nvm.sh
2.安装node.js
1.查看已安装 node.js 版本
nvm ls
2.查看可安装的 node.js 版本
nvm ls-remote
3.安装长期支持版 v8.10.0 (Latest LTS: Carbon)
nvm install v8.10.0
4.查看已安装 node.js 版本
nvm use 版本号
3.安装npm
由于新版的nodejs已经集成了npm,所以之前npm也一并安装好了
1.查看npm 版本
npm -v
2.更新到最新版本
npm install npm -g
4.淘宝npm镜像 cnpm
国内直接使用 npm 的官方镜像是非常慢的,这里推荐使用淘宝 NPM 镜像。
用npm 安装 cnm
npm install -g cnpm --registry=https://registry.npm.taobao.org
5.安装nrm
nrm(npm registry manager )是npm的镜像源管理工具,有时候国外资源太慢,那么我们可以用这个来切换镜像源。(一般情况下可以直接使用上面安装的cnpm就可以了)
1.安装全局 nrm
npm install -g nrm
2 安装完后 列出可用的源:
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