Install Brew
中科大镜像使用,加速安装
首先,需要确保系统中安装了 bash、git 和 curl,对于 macOS 用户需额外要求安装 Command Line Tools (CLT) for Xcode。
- 对于 macOS 用户,系统自带 bash、git 和 curl,在命令行输入
xcode-select --install
安装 CLT for Xcode 即可。 - 对于 Linux 用户,系统自带 bash,仅需额外安装 git 和 curl。
接着,在终端输入以下几行命令设置环境变量:
1 | if [[ "$(uname -s)" == "Linux" ]]; then BREW_TYPE="linuxbrew"; else BREW_TYPE="homebrew"; fi |
最后,在终端运行以下命令以安装 Homebrew / Linuxbrew:
1 | # 从本镜像下载安装脚本并安装 Homebrew / Linuxbrew |
检查是否安装成功
1 | brew update |
fatal: unable to access 'https://github.com/': Could not resolve proxy: aproxy
1 | git config --global --unset http.proxy |
uninstall brew
1 | # uninstall |
Install Node and npm by NVM
NVM 安装 (node version manager)
install nvm by brew link
1 | brew install nvm |
install by
1 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash |
报错 “zsh: command not found: nvm”
原因:安装未成功 创建一个nvm的文件用来装载nvm的内容 在命令行执行:
1 | mkdir ~/.nvm |
需要在~/.zshrc 文件里面增加以下配置 用vim打开该文件
1 | vim ~/.zshrc |
如果有swp文件妨碍修改,删掉即可 按 i 进入书写模式,黏贴以下代码
1 | export NVM_DIR="$HOME/.nvm"[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm[ -s "/usr/local/opt/nvm/etc/bash_completion" ] && . "/usr/local/opt/nvm/etc/bash_completion" |
按 esc 键 :wq 保存退出
执行命令使配置生效:
1 | source ~/.zshrc |
再次执行brew install nvm
nvm 安装 Node and npm
查看 version
1 | nvm ls-remote |
安装版本
1 | nvm install <version> |
查看本地安装的 node 版本
1 | nvm list |
指定使用的版本
1 | nvm use <version> # v15.12.0 |
检查使用的 node 版本
1 | nvm currentornode -version |
卸载版本
1 | nvm uninstall <version> |
Install Node and npm
不推荐使用官方的安装包安装(https://nodejs.org/en/download/)
原因:since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally
Solve EACCES error
If you see an EACCES
error when you try to install a package globally, you can either:
- Reinstall npm with a node version manager (recommended),
do not need to remove your current version of npm or Node.js before installing a node version manager.
- Manually change npm's default directory
卸载 Node & npm completely
1 | cd /cd usrcd localcd include sudo rm -R nodecd ../libsudo rm -R node_modulescd ../binsudo rm -R node |
use brew install node
1 | brew uninstall nodebrew doctorbrew cleanup --prune-prefix# installbrew install node;which node # => /usr/local/bin/nodeexport NODE_PATH='/usr/local/lib/node_modules' # <--- add this ~/.bashrc |
npm 使用
安装 package
1 | npm install <pacakge name> --save |
卸载 package
1 | npm uninstall <pacakge name> |