因为要写不同的项目,所以会涉及到不同的业务场景,需要的node版本也不会一样,所以今天干脆安装一下nvm
,用来管理我的node
- 前面步骤都差不多,都是先卸载掉本地
node
然后再安装新的,避免冲突和更多的麻烦 - 卸载本地
node
// 依次执行以下指令,卸载本地node
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
- 检查一下
node -v //command not found
npm -v //command not found
- 好,开始安装
nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | bash
报错一:
curl: (35) error:02FFF020:system library:func(4095):Broken pipe
尝试了替换hosts
文件,重装,各种各种,然后解决方案:
// 使用gitee镜像安装
git clone https://gitee.com/mirrors/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
hetingting@hetingtingdeMacBook-Pro ~ % git clone https://gitee.com/mirrors/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
Cloning into '/Users/hetingting/.nvm'...
remote: Enumerating objects: 8192, done.
remote: Counting objects: 100% (8192/8192), done.
remote: Compressing objects: 100% (4101/4101), done.
remote: Total 8192 (delta 5263), reused 6340 (delta 4015), pack-reused 0
Receiving objects: 100% (8192/8192), 2.39 MiB | 458.00 KiB/s, done.
Resolving deltas: 100% (5263/5263), done.
Note: switching to 'v0.37.2'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 4b947ec v0.37.2
安装成功!
- 配置环境变量
vi ~/.bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
- 报错
E45: 'readonly' option is set (add!to override)
然后只需要在执行:wq
的时候,在后面加个感叹号,强制保存就好了
- 继续执行指令
source .bash_profile
source ~/.zshrc
- 安装成功