最近重装了环境,顺便记录一点。
这里记录一下我在mac上安装node的过程,及使用nrm切换镜像的工具来随时选择网络良好的镜像。
下载node.js,mac多种方式,一种是下载pkg直接安装,一种是通过brew来安装。
1.1 通过官网下载pkg直接安装,地址:node官网
运行安装包,安装
继续继续安装
安装完成以后运行终端,输入
node -v
和
npm -v
因为自带了npm,所以都可以正常看到版本号。证明安装成功。
$ node -v
v10.16.3
$ npm -v
6.9.0
npm默认的仓库地址是在国外网站,速度较慢,建议大家设置到淘宝镜像。但是切换镜像是比较麻烦的。推荐一款切换镜像的工具:nrm
我们首先安装nrm,这里-g
代表全局安装
npm install nrm -g
安装完成以后我们可以使用 nrm ls 命令查看查看npm的仓库列表,带*的就是当前选中的镜像仓库:
$ nrm ls
* npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
通过nrm use taobao
来指定要使用的镜像源:
$ nrm use taobao
Registry has been set to: https://registry.npm.taobao.org/
$ nrm ls
npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
然后通过nrm test npm
来测试速度:
$ nrm test npm
npm ---- 1735ms
$ nrm test taobao
* taobao - 236ms
可以看到速度差距还是很大的。
文章后面补充一个通过brew安装node的方法:
先查看mac上有没有安装brew,可以在终端输入:brew
$ brew
Example usage:
brew search [TEXT|/REGEX/]
brew info [FORMULA...]
brew install FORMULA...
brew update
brew upgrade [FORMULA...]
brew uninstall FORMULA...
brew list [FORMULA...]
Troubleshooting:
brew config
brew doctor
brew install --verbose --debug FORMULA
Contributing:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
Further help:
brew commands
brew help [COMMAND]
man brew
https://docs.brew.sh
如果出现上面的反应就说明安装了,如果没有安装可以去安装:brew安装.
安装命令:brew install node
和 brew install npm
补充:
全局安装Vue, 输入 npm install -g vue