How to install NVM (Node Version Manager) on macOS
Hafiz Muhammad Ahmed
AI Engineer | Build AI Agents and Workflow Automations using (n8n | LangGraph | Crew AI) | Pursuing MSc in AI | Develop AI Applications using (Next.js | FastAPI)
Recently at work, I faced a situation where the project required Node.js version 20, but my computer had the latest version, Node.js 22. I solved this problem using NVM (Node Version Manager) to set up the specific Node.js version needed. In this blog, I would like to share how I did it.
To install NVM (Node Version Manager) on macOS, you can follow these steps:
1. Install Homebrew:
If you don’t have Homebrew installed, you can install it by opening Terminal and running the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Install NVM using Homebrew:
Install NVM using Homebrew: Once Homebrew is installed, you can use it to install NVM. Run the following command in Terminal:
brew install nvm
3. Source NVM in your shell profile:
Add the following lines to your shell profile file (e.g., ~/.bashrc, ~/.zshrc, or ~/.bash_profile):
export NVM_DIR=~/.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
Then, restart your terminal or run source ~/.your_shell_profile to apply the changes.
4. Verify Installation
You can verify that NVM is installed by running:
nvm --version
5. Install Node.js using NVM
You can now use NVM to install Node.js. For example, to install the latest LTS version, run:
nvm install --lts
To install a specific Node version, run:
nvm install 18
Next, implement the installed version, run:
nvm use 18
Remember to restart your terminal after making changes to the shell profile to apply the modifications. After installation, you can use NVM to easily switch between Node.js versions.
I hope this guide helps you smoothly manage different Node.js versions for your projects. Thanks for reading, and happy coding! ???