Post

How to Install Node.js on macOS

Install nvm on macOS so you can easily manage and switch between Node.js versions.

How to Install Node.js on macOS

If you work with JavaScript frameworks, nvm (Node Version Manager) is indispensable for managing multiple versions of Node.js. It simplifies the process of switching between Node.js versions depending on your project requirements. Here’s how you can easily install nvm and Node.js on your macOS system.

1. Installing Homebrew

First, you’ll need Homebrew, a popular package manager for macOS, to install nvm. If you don’t have Homebrew installed, check out my How to Install Homebrew on macOS post for detailed instructions on how to install Homebrew.

2. Installing NVM

Once Homebrew is installed, you can install nvm by running:

1
brew install nvm

3. Configuring Your Shell Profile

To make nvm available every time you open a new terminal window, you need to add it to your shell profile.

For bash or zsh (common macOS shells), add the following line to your .bash_profile, .bashrc, or .zshrc file:

1
2
export NVM_DIR="$HOME/.nvm"
source $(brew --prefix nvm)/nvm.sh

After editing the file, apply the changes by running:

1
2
source ~/.bash_profile   # for bash users
source ~/.zshrc          # for zsh users

4. Installing Node.js with NVM

With nvm installed and configured, you can now install the latest version of Node.js by running:

1
nvm install node

This will install the most recent stable release of Node.js.

5. Managing Node.js Versions

One of the main benefits of nvm is that it allows you to manage multiple Node.js versions. Here’s how to do that:

Listing Available Versions

To see a list of all available Node.js versions that can be installed using nvm, run:

1
nvm ls-remote

Installing a Specific Version

To install a specific version of Node.js (for example, version 16), use:

1
nvm install 22

Switching Between Versions

Once you have multiple versions of Node.js installed, you can switch between them by running:

1
nvm use 16

This will switch your active Node.js version to 16.

Setting a Default Node.js Version

If you always want to use a particular version of Node.js as the default, set it by running:

1
nvm alias default 22

Now, every time you open a new terminal window, Node.js version 16 will be used unless you manually switch it.


By following these steps, you’ll have nvm and Node.js installed, allowing you to effortlessly manage and switch between Node.js versions for all your projects.

☕ Support My Work

If you found this post helpful and want to support more content like this, you can buy me a coffee!

Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏

This post is licensed under CC BY 4.0 by the author.