macos:用homebrew安装node/安装vue-cli( node v18.15.0/ Homebrew 4.0.10-119)
一,用brew安装node
liuhongdi@liuhongdideMacBook-Pro Homebrew % brew install node@18 ==> Downloading https://formulae.brew.sh/api/formula.jws.json #=#=# ==> Fetching node@18 ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/node%4018-18.15.0.monterey.bottle.1.tar.gz ######################################################################## 100.0% ==> Pouring node@18-18.15.0.monterey.bottle.1.tar.gz ==> Caveats node@18 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 node@18 first in your PATH, run: echo 'export PATH="/usr/local/opt/node@18/bin:$PATH"' >> ~/.zshrc For compilers to find node@18 you may need to set: export LDFLAGS="-L/usr/local/opt/node@18/lib" export CPPFLAGS="-I/usr/local/opt/node@18/include" ==> Summary 🍺 /usr/local/Cellar/node@18/18.15.0: 2,343 files, 56.6MB ==> Running `brew cleanup node@18`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
查看node的版本,
如果找不到,按照安装时控制台的提示添加path
liuhongdi@liuhongdideMacBook-Pro Homebrew % node -v zsh: command not found: node liuhongdi@liuhongdideMacBook-Pro Homebrew % /usr/local/opt/node@18/bin/node -v v18.15.0 liuhongdi@liuhongdideMacBook-Pro Homebrew % echo 'export PATH="/usr/local/opt/node@18/bin:$PATH"' >> ~/.zshrc liuhongdi@liuhongdideMacBook-Pro Homebrew % source ~/.zshrc liuhongdi@liuhongdideMacBook-Pro Homebrew % node -v v18.15.0
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/05/macos-yong-homebrew-an-zhuang-node-an-zhuang-vuecli-node/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,配置npm的安装源:
1,查看npm的配置
liuhongdi@liuhongdideMacBook-Pro ~ % npm config list ; "builtin" config from /usr/local/Cellar/node@18/18.15.0/lib/node_modules/npm/npmrc prefix = "/usr/local" ; node bin location = /usr/local/Cellar/node@18/18.15.0/bin/node ; node version = v18.15.0 ; npm local prefix = /Users/liuhongdi ; npm version = 9.5.0 ; cwd = /Users/liuhongdi ; HOME = /Users/liuhongdi ; Run `npm config ls -l` to show all defaults.
2,配置源为淘宝
liuhongdi@liuhongdideMacBook-Pro ~ % npm config set registry https://registry.npm.taobao.org
3,查看效果:
liuhongdi@liuhongdideMacBook-Pro ~ % npm config list ; "builtin" config from /usr/local/Cellar/node@18/18.15.0/lib/node_modules/npm/npmrc prefix = "/usr/local" ; "user" config from /Users/liuhongdi/.npmrc registry = "https://registry.npm.taobao.org/" ; node bin location = /usr/local/Cellar/node@18/18.15.0/bin/node ; node version = v18.15.0 ; npm local prefix = /Users/liuhongdi ; npm version = 9.5.0 ; cwd = /Users/liuhongdi ; HOME = /Users/liuhongdi ; Run `npm config ls -l` to show all defaults.
可见已生效
注意:如果不配置国内源,npm安装时会很慢
三,安装vue-cli
1,用npm安装
liuhongdi@liuhongdideMacBook-Pro ~ % npm install -g @vue/cli
2,查看vue-cli版本:
liuhongdi@liuhongdideMacBook-Pro ~ % vue --version @vue/cli 5.0.8
四,查看homebrew的版本:
liuhongdi@liuhongdideMacBook-Pro poem % brew --version Homebrew 4.0.10-119-g931327d Homebrew/homebrew-core (git revision 3d8b912faa5; last commit 2023-04-01) Homebrew/homebrew-cask (git revision 5d24927a9d; last commit 2023-04-01)