NVM(Node Version Manager) 설치하기 (for Mac)

NVM 설치

설치

최신버전 설치는 nvm github에서 확인가능

1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

설치여부 확인

nvm 확인하면 not found 에러남

1
2
nvm ls
## zsh: command not found: nvm

bash 에 경로 추가

1
vi .zprofile  

bash profile 안에 NVM_DIR path 설정 추가

1
2
3
4
5
#.zprofile

## ADD NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

profile 다시 적용

1
source ~/.zprofile

nvm 확인

1
2
3
4
5
6
nvm ls

#-> system
#iojs -> N/A (default)
#node -> stable (-> N/A) (default)
#unstable -> N/A (default)

nvm 으로 node 설치

node 설치

1
nvm install 14  #version 14 의 최신버전이 설치됨

node 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
nvm ls

#-> v14.16.0
## system
#default -> 14 (-> v14.16.0)
#iojs -> N/A (default)
#unstable -> N/A (default)
#node -> stable (-> v14.16.0) (default)
#stable -> 14.16 (-> v14.16.0) (default)
#lts/* -> lts/fermium (-> v14.16.0)
#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.0 (-> N/A)
#lts/erbium -> v12.21.0 (-> N/A)
#lts/fermium -> v14.16.0
1
2
node -v
#v14.16.0

NVM 명령어 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Example:
nvm install 8.0.0 Install a specific version number
nvm use 8.0 Use the latest available 8.0.x release
nvm run 6.10.3 app.js Run app.js using node 6.10.3
nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3
nvm alias default 8.1.0 Set default node version on a shell
nvm alias default node Always default to the latest available node version on a shell

nvm install node Install the latest available version
nvm use node Use the latest version
nvm install --lts Install the latest LTS version
nvm use --lts Use the latest LTS version

nvm set-colors cgYmW Set text colors to cyan, green, bold yellow, magenta, and white

Note:
to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)