Install NVM (Node Version Manager)
How to install NVM and install and activate a target Node.js version
You can install multiple version of Node.js using NVM.
Node.js vs NVM
Even for a first-time install of Node.js, you could install Node.js using NVM, as covered in the NVM option on the Node.js install doc. One advantage is that it does not required sudo, which is necessary on macOS when installing Node.js.
To install Node.js alone without NVM, see this gist.
See instructions below from the NVM Install and update docs. See also Install NVM with Homebrew guide.
Install NVM:
- Use
curl
. This works on macOS or Linux.$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
- Use Brew on macOS.
$ brew install nvm
That will automatically add this code to your .bash_profile
or .zshrc
file. But you might want move it to a file that is more appropriate for your setup.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"