安装
brew
1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
安装
NVM
1
brew install nvm
配置环境变量
在环境变量文件中加入如下内容,如zsh
即为~/.zshrc
1
2export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh安装指定版本的
node
1
2
3
4
5
6
7
8nvm install 8.17.0
Downloading and installing node v8.17.0...
Downloading https://nodejs.org/dist/v8.17.0/node-v8.17.0-darwin-x64.tar.xz...
######################################################################################################################################################### 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v8.17.0 (npm v6.13.4)
Creating default alias: default -> 8.17.0 (-> v8.17.0)nvm
常用命令1
2
3
4nvm ls-remote # 查看所有的node可用版本
nvm install xxx # 下载你想要的版本
nvm use xxx # 使用指定版本的node
nvm alias default xxx # 每次启动终端都使用该版本的node问题解决
问题如下:
1
2
3
4
5
6
7
8nvm ls-remote
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/opt/curl-openssl/bin/curl
Reason: image not found
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/opt/curl-openssl/bin/curl
Reason: image not found
N/A解决方法:
1
2
3brew switch openssl 1.0.2s
Cleaning /usr/local/Cellar/openssl/1.0.2s
Opt link created for /usr/local/Cellar/openssl/1.0.2s