If you are a developer working on a Mac, you may have come across the need to manage multiple versions of Node.js. This is where NVM (Node Version Manager) comes in handy.
NVM allows you to easily switch between different versions of Node.js on your machine, making it a must-have tool for any developer. In this tutorial, we will walk through the steps to install NVM on your Mac.
Step 1: Install Homebrew
To install NVM on your Mac, we first need to install Homebrew. Homebrew is a package manager for macOS that makes it easy to install and manage software packages. Open your terminal and enter the following command:
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
This command will download and run the Homebrew installation script.
Step 2: Install NVM
Once Homebrew is installed, we can use it to install NVM. In your terminal, run the following command:
brew install nvm
This will install NVM on your Mac.
Step 3: Configure NVM
After installing NVM, we need to configure it so that it is properly set up in our terminal. Open your terminal and enter the following command:
echo ‘export NVM_DIR=”$HOME/.nvm”‘ >> ~/.bash_profile
echo ‘[ -s “$NVM_DIR/nvm.sh” ] && \. “$NVM_DIR/nvm.sh”‘ >> ~/.bash_profile
These commands add the necessary configurations to your bash profile file.
Step 4: Activate Changes
Now that we have made changes to our bash profile, we need to reload it in order for the changes to take effect. Run the following command in your terminal:
This will reload your bash profile and activate the changes we made.
Step 5: Verify Installation
To verify that NVM is installed correctly, run the following command in your terminal:
If NVM is installed, you should see the version number printed out in your terminal.
Step 6: Install Node.js
Now that NVM is installed and configured, we can use it to install Node. To install the latest version of Node.js, run the following command:
nvm install node
This will install the latest version of Node.js on your machine.
Switching Between Node.js Versions
If you have multiple versions of Node.js installed using NVM, you can easily switch between them. To switch to a specific version of Node.js, run the following command:
Congratulations! You have successfully installed NVM on your Mac.
Now you can easily manage multiple versions of Node.js on your machine using NVM. Enjoy coding!