참고사이트로컬 버전 nvm 활용nvm 설치nvm 잘 설치됐는지 검증node 버전 설치node 버전 확인다른 버전 사용 (npm 버전도 같이 변경됨)default 버전 변경프로젝트에서 동료들과 nvm 버전 맞추기
참고사이트
로컬 버전 nvm 활용
nvm 설치
- 아래 명령어로 설치하면
.zshrc
의 환경변수도 알아서 바꿔준다.
# nvm 설치 $ sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
설치 결과 출력 콘솔
usercontent.com/creationix/nvm/v0.33.1/install.sh | bashhttps://raw.github Password: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11388 100 11388 0 0 19805 0 --:--:-- --:--:-- --:--:-- 19805 => nvm is already installed in /Users/night-ohl/.nvm, trying to update using git => => Compressing and cleaning up git repository Enumerating objects: 8012, done. Counting objects: 100% (8012/8012), done. Delta compression using up to 8 threads Compressing objects: 100% (7936/7936), done. Writing objects: 100% (8012/8012), done. Total 8012 (delta 5361), reused 2650 (delta 0) Computing commit graph generation numbers: 100% (1940/1940), done. => nvm source string already in /Users/night-ohl/.bashrc => bash_completion source string already in /Users/night-ohl/.bashrc => You currently have modules installed globally with `npm`. These will no => longer be linked to the active version of Node when you install a new node => with `nvm`; and they may (depending on how you construct your `$PATH`) => override the binaries of modules installed with `nvm`: /usr/local/lib ├── applesign@3.6.0 ├── create-react-native-app@3.5.1 ├── expo-cli@3.20.9 ├── react-devtools@4.8.2 ├── react-native-create-library@3.1.2 └── react-native-vector-icons@7.1.0 => If you wish to uninstall them at a later point (or re-install them under your => `nvm` Nodes), you can remove them from the system Node as follows: $ nvm use system $ npm uninstall -g a_module => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm night-ohl@MacBook-Pro[:~/Desktop/nodeEnv$
nvm 잘 설치됐는지 검증
$ command -v nvm

위 그림처럼 nvm 이라고 출력된다면 잘 설치된 것임.
node 버전 설치
# node 설치 $ nvm install node #최신 버전 설치 $ nvm install 10.22.0 #특정 버전 설치
node 버전 확인
# 현재 사용중 노드 버전 확인 $ node -v # nvm에 설치된 노드 버전 리스트 확인 $ nvm ls
nvm ls 결과
night-ohl@MacBook-Pro[:~/Desktop/nodeEnv$ nvm ls -> v10.22.0 v15.2.1 system default -> node (-> v15.2.1) node -> stable (-> v15.2.1) (default) stable -> 15.2 (-> v15.2.1) (default) iojs -> N/A (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.23.0 (-> N/A) lts/erbium -> v12.19.1 (-> N/A) lts/fermium -> v14.15.1 (-> N/A)
다른 버전 사용 (npm 버전도 같이 변경됨)
$ nvm use v14.6.0 # 이렇게 구체적인 버전 명시도 가능 $ nvm use 16 Now using node v16.9.1 (npm v7.21.1) $ node -v v16.9.1 $ nvm use 14 Now using node v14.18.0 (npm v6.14.15) $ node -v v14.18.0 $ nvm install 12 Now using node v12.22.6 (npm v6.14.5) $ node -v v12.22.6
default 버전 변경
$ nvm alias default v12.19.0
프로젝트에서 동료들과 nvm 버전 맞추기
- 프로젝트에 .nvmrc 파일을 만들고 거기에 프로젝트에서 사용할 노드 버전을 명시한다
nvm install & nvm use
명령을 통해 명시된 노드버전으로 세팅한다.
당연하지만 이미 해당 버전이 설치되어 있다면
nvm use
만 하면 된다.
$ nvm install # 프로젝트에 명시된 노드버전이 내 로컬에 설치되어 있지 않다면 설치하기 $ nvm use # 프로젝트의 .nvmrc 파일에 명시된 노드버전을 사용한다.