# Node Mac上的安装方式

来源:互联网 发布:淘宝商品数据包下载 编辑:程序博客网 时间:2024/05/22 13:32

Node Mac上的安装方式

终端安装 homebrew

$ ruby -e "$(curl -fsSL https:/raw.githubusercontent.com/Homebrew/install/master/install)"

brew安装node

  • 更新 brew

    $ brew update
  • 确保brew安全可靠

    $ brew doctor

    可能会出现如下情况 ,可针对逐条处理:

    Warning: Some directories in /usr/local/share/man aren’t writable.
    This can happen if you “sudo make install” software that isn’t managed
    by Homebrew. If a brew tries to add locale information to one of these
    directories, then the install will fail during the link step.

    You should probably sudo chown -R $(whoami) them:
    /usr/local/share/man/man5

    /usr/local/share/man/man7

  • 将brew 添加到环境变量中,并保存 bash 或者 profile中

    $ export PATH="usr/local/bin:$PATH"

brew 安装完成。如果在上面安装中出现如下错误信息

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link on these:

就需要如下操作

  • 清除brew的link

    $ brew cleanup
  • 删除node文件,完全卸载node和npm

    $ sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

    或者

    $ sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules

    或者这样

    • 在/usr/local/lib目录下,删除任何与node和 node_modules有关的目录;

    • 在/usr/local/include 目录下,删除任何与node 和 node_modules有关的目录;

    • 如果你是通过 brew install node 安装的node,则在终端执行brew uninstall node ,并在home目录下查找 locallibinclude文件夹,删除任何与nodenode_modules有关的目录;
    • /usr/local/bin目录下,删除任何与 node 执行文件;
    • 最后下载 nvm ,跟随它的介绍安装node。当然,你也可以通过npm来安装最新版本的Node。

通过brew 安装 node 和npm

$ brew link node$ brew uninstall node$ brew install node

测试

通过安装一个模块测试node 和npm 是否安装成功 express

$ npm install -g express 

如果按照成功,那么 npm 和node就都安装成功了

查看版本

$ node -v$ npm -v