How to install NVM (Node Version Manager) on macOS
Hi, I’m Suki, front-end developer. Meanwhile working on my personal project, I encountered a situation where the project required Node version 18, while my computer had the default Node version 21.. I implemented a solution using NVM to set up a specific node version. In this blog, I would like to share with you how I did it.
To install NVM (Node Version Manager) on macOS, you can follow these steps:
- 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 helps! Thanks for reading and happy coding. ❤️😊