Setting up NVM (Node Version Manager) on macOS,
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash) …
Install NVM:
Open a terminal window and run the following command to download the NVM installation script from the official GitHub repository:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Open your shell configuration file in a text editor. Depending on your shell, it could be ~/.bash_profile
, ~/.bashrc
, ~/.zshrc
, or ~/.profile
. For example, to edit ~/.zshrc
, you can use the following command:
nano ~/.zshrc
Add the following lines to the bottom of the file:
These lines will initialize NVM whenever you start a new shell session.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
These lines will initialize NVM whenever you start a new shell session.
Save the changes and exit the text editor. In Nano, you can do this by pressing Ctrl + X
, then Y
, and then Enter
.
After saving the changes, you need to reload your shell configuration for the changes to take effect. You can do this by either restarting your terminal or running
nvm --version
Install Node.js:
Once NVM is installed, you can use it to install Node.js. For example, to install the latest LTS version of Node.js, you can run:
This command installs the latest Long-Term Support (LTS) version of Node.js.
nvm install --lts
nvm install 14 // if you need node version 14 installed.
Set Default Node.js Version (Optional)
If you want to set a default Node.js version to use, you can run:
// nvm alias default <version>
nvm alias default 14 // installed node 14 etc
Verify Node.js Installation
You can verify that Node.js is installed correctly by running:
node -v // v14 etc. <version> installed.