一 使用brew升级node 1 解释 homebrew 可以理解成osx的软件管理工具,粗俗点说就是mac界的qq软件助手之类的东西。所以通过brew,安装什么chrome浏览器啊、atom编辑器之类的可视化工具也是可以的哦。
npm 是Node.js界的程序/模块管理工具,也就是说npm只管理那些服务于JavaScript社区的程序。而且跨平台,windows和osx,以及其他unix like操作系统都可以用
2 更新homebrew
brew update//如果出现The /usr/local directory is not writable.则需要更改权限 ,然后输入:sudo chown -R $(whoami) /usr/local
1
2
3
4
5
1
2
3
4
5
3 升级完以后,会弹出这个
Homebrew no longer needs to have ownership of /usr/local. If you wish you canreturn /usr/local to its default ownership with sudo chown root:wheel /usr/local
1
2
3
1
2
3
3.1 按提示输入下边的命令,更改会原来的权限
sudo chown root:wheel /usr/local
1
1
4 更新node
brew upgrade node
1
1
4.1升级完以后,出现下边信息,表示此版本是英文版的,可以忽略。如果想获取其他版本的,就按着提示输入吧!!
Please note by default only English locale support is provided. If you needfull locale support you should either rebuild with full icu: brew reinstall node --with-full-icu
or add full icu data at runtime following: https://github.com/nodejs/node/wiki/Intl#using-and-customizing-the-small-icu-buildBash completion has been installed to: /usr/local/etc/bash_completion.d
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
5 其他错误
Downloading http://nodejs.org/dist/v0.10.2/node-v0.10.2.tar.gz ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/node/0.10.2 ==> make install Warning: Could not link node. Unlinking... Error: The brew link
step did not complete successfully The formula built, but is not symlinked into /usr/local You can try again using `brew link node'
1
1
5.1根据提示输入
brew link node
1
1
5.2 出现另一个错误,意思是nodejs已经创建,所以需要删除或者覆盖现有版本
Linking /usr/local/Cellar/node/0.10.2... Warning: Could not link node. Unlinking... Error: Could not symlink file: /usr/local/Cellar/node/0.10.2/bin/npm /usr/local/bin/npm may already exist. /usr/local/bin may not be writable.
1
1
5.3 最终解决方法如下:
方法1: 手动删除/usr/local/bin 下面的node和npm文件 方法2: 覆盖现有版本brew link --overwrite node
二 不使用brew更新node 注意: 没试过 这里记录一下 mac 升级 node.js 的简易方法。 切记要按照步骤:
第一步,先查看本机node.js版本: $ node -v第二步,清除node.js的cache: $ sudo npm cache clean -f第三步,安装 n 工具,这个工具是专门用来管理node.js版本的,别怀疑这个工具的名字,是他是他就是他,他的名字就是 "n" $ sudo npm install -g n第四步,安装最新版本的node.js $ sudo n stable第五步,再次查看本机的node.js版本: $ node -v
这里的第一步和第五步完全可以省略,只是个人比较喜欢查看一下,满足自己的眼睛。第二步比较重要,有些可以省略有些就不行,一律使用准没错。