Qingquan-Li / blog

My Blog
https://Qingquan-Li.github.io/blog/
132 stars 16 forks source link

macOS安装及卸载Node.js #103

Open Qingquan-Li opened 6 years ago

Qingquan-Li commented 6 years ago

开发环境:

参考:


一、安装 node

使用 Homebrew 安装 node 8.11.3 (截止 2018.06 LTS 版本为 8.11.3 ):

➜  /Users/fatli > brew install node@8
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node@8-8.11.3.sierra.bottle
######################################################################## 100.0%
==> Pouring node@8-8.11.3.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/node@8/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/node@8/lib
    CPPFLAGS: -I/usr/local/opt/node@8/include

==> Summary
🍺  /usr/local/Cellar/node@8/8.11.3: 4,430 files, 47.2MB

创建软链接到 /usr/local/bin :

➜  /Users/fatli > ln -s /usr/local/Cellar/node@8/8.11.3/bin/node  /usr/local/bin
➜  /Users/fatli > node -v
v8.11.3
➜  /Users/fatli > ln -s /usr/local/Cellar/node@8/8.11.3/bin/npm  /usr/local/bin
➜  /Users/fatli > npm -v
5.6.0
➜  /Users/fatli > ln -s /usr/local/Cellar/node@8/8.11.3/bin/npx  /usr/local/bin
➜  /Users/fatli > npx -v
9.7.1


二、卸载

使用 Homebrew 安装的软件包非常易于卸载。不是使用 Homebrew 安装的 node ,卸载方法点解这里

➜  /Users/fatli > brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-10.4.1.sierra.bottle.t
Already downloaded: /Users/fatli/Library/Caches/Homebrew/node-10.4.1.sierra.bottle.tar.gz
==> Pouring node-10.4.1.sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/node/10.4.1: 6,793 files, 59.8MB
➜  /Users/fatli > brew uninstall node
Uninstalling /usr/local/Cellar/node/10.4.1... (6,793 files, 59.8MB)


三、brew install node 和 brew install node@8

  1. 使用 brew install node (不指定 node 版本号)命令安装 node ,文件分布:

    • /usr/local/Cellar : node
    • /usr/local/opt : node 、 node.js 、 node@10 、 npm
    • /usr/local/bin : node 、 npm 、 npx
  2. 使用 brew install node@8 (指定 node 版本号)命令安装 node ,文件分布:

    • /usr/local/Cellar : node@8
    • /usr/local/opt : node@8
    • /usr/local/bin : 无


  1. 使用 brew install node (不指定 node 版本号)命令安装 node ,将安装最新版的 node ,并且会自动在 /usr/local/bin 目录下创建“替身“(即软链接)。
  2. 使用 brew install node@8 (指定 node 版本号)命令安装 node ,不会自动在 /usr/local/bin 目录下创建“替身“(即软链接),需要使用 ln -s 命令在 /usr/local/bin 目录下创建软链接。( brew search node 查看可指定安装的版本)


  1. 使用 brew uninstall node (不指定版本号)命令卸载 node 软件包后,需要手动到 /usr/local/bin 目录下删除相应到 npm 、 npx 替身 ( node 替身会被自动删除)。
  2. 使用 brew uninstall node@8 (指定版本号)命令安装的 node 软件包后,使用 ln -s 命令创建在 /usr/local/bin 目录下的 node 、 npm 、 npx 替身(软链接)会自动随着 brew uninstall node@8 卸载而被删除,不需要手动去删除。


附:更新 npm

参考:

实例:不更新 node,单独更新 npm 5.6.0 → 6.14.4(此时时间为 2020.04.07):

update npm