Node.js: Switch Node Version with Node Version Manager
오늘은 새로운 Frontend build tool, Vite를 사용한 프로젝트를 진행하려는데 NodeJS version이 낮아 지원하지 않아 NodeJS version을 바꾸는 법에 대해 알아보도록 하자.
Prerequisites
Homebrew
must be installed on your system.
Install Node Version Manager
1
2
$ brew update
$ brew install nvm
After Download NVM
zsh may not recognize nvm command and return an error message like: zsh: command not found: nvm
. To fix this issue, open ~/.zshrc
and add the NVM_DIR to the file.
1
2
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
You may restart the terminal or VSCode to run nvm
command
Install and Switch NodeJS with NVM
To see available versions:
1
$ nvm ls-remote
With Node Version Manager, different versions of node can be installed:
1
2
$ nvm install node ## Installing latest version of NodeJS
$ nvm install 14 ## Installing NodeJS 14.x version
After the install, you can check what versions are installed:
1
$ nvm ls
To switch the Node version, use:
1
2
3
4
# targeted node version will be used after the installation
$ nvm install <node_version>
# use `use` command
$ nvm use <node_version>
Then you can verify your Node version with:
1
2
3
4
# with nvm command
$ nvm current
# with node version check
$ node --version
References:
This post is licensed under CC BY 4.0 by the author.