Dev./Node.js
[Node.js] nvm으로 버전 변경하기
인쥭
2021. 7. 26. 16:51
반응형
참고
- macBook 기준
[~] brew install nvm
[~] mkdir ~/.nvm
[~] vi ~/.zshrc
// 생략
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.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
// 위 내용을 .zshrc 최하단에 추가
[~] source ~/.zshrc
[~] nvm --version
0.38.0
[~] nvm install v12.22.3
Downloading and installing node v12.22.3...
Downloading https://nodejs.org/dist/v12.22.3/node-v12.22.3-darwin-x64.tar.xz...
############################################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v12.22.3 (npm v6.14.13)
Creating default alias: default -> v12.22.3
[~] node -v
v12.22.3
[~]
- nvm install [버전]: 특정 버전을 설치
- 추가로 node 버전을 설치한 경우, 다음과 같이 작업이 가능하다.
[~] nvm install v16.3.0
Downloading and installing node v16.3.0...
Downloading https://nodejs.org/dist/v16.3.0/node-v16.3.0-darwin-x64.tar.xz...
############################################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v16.3.0 (npm v7.15.1)
[~] node -v
v16.3.0
[~] nvm use v12.22.3
Now using node v12.22.3 (npm v6.14.13)
[~] node -v
v12.22.3
[~] nvm alias default v12.22.3
default -> v12.22.3
[~] nvm ls
-> v12.22.3
v16.3.0
system
default -> v12.22.3
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.3.0) (default)
stable -> 16.3 (-> v16.3.0) (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.3
lts/fermium -> v14.17.3 (-> N/A)
[~]
- nvm use [버전]: 특정 버전을 사용
- nvm alias default [버전]: 터미널 실행시 기본 버전
- nvm ls: 설치된 버전을 확인
추가
- gyp: No Xcode or CLT version detected! 에러 발생시 xcode를 재설치해주자.
[~] xcode-select --print-path
[~] sudo rm -rf [위 명령어에서 나온 경로]
[~] xcode-select --install
- print-path를 통해 xcode 설치 경로를 확인한 후, 해당 내용을 삭제한다.
- 일반적으로 /Library/Developer/CommandLineTools일텐데, sudo rm -rf /Library/Developer/CommandLineTools 해주면 된다.