How To Install NVM On MacOS With Homebrew - TecAdmin
Node Version Manager (NVM) is popular among developers for installing and managing multiple versions of Node.js on a single machine. This allows developers to work on multiple projects that require different versions of Node.js. NVM installs Node.js under the user’s home directory, ensuring that Node.js versions do not conflict between users on shared systems. On macOS, there are several methods available to install NVM, but one of the most popular and efficient ways is using Homebrew, the renowned package manager for macOS.
This tutorial will provide you with step-by-step instructions for installing NVM on macOS using Homebrew, enabling you to set up a flexible Node.js development environment with ease.
Step 1: Install Homebrew
If you don’t have Homebrew installed on your macOS, you can install it by pasting the following command in the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"For more instruction visit Homebrew installation tutorial.
Step 2: Install NVM on macOS
- Before installing any packages, it’s always a good idea to update Homebrew to the latest version and update the formulae. brew update
- After that, you can easily install NVM using the following command: brew install nvm
- Now, configure the required environment variables. Edit the following configuration file in your home directory vim ~/.zprofile
- Add the below lines to ~/.zprofile ( or ~/.bashrc for older macOS versions) export NVM_DIR="$HOME/.nvm" [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"
Press ESC + :wq to save and close your file.
- Next, load the environment variables to the current shell environment. From the next login, it will automatically loaded. source ~/.zprofile
That’s it. The NVM has been installed on your macOS system. Go to next step to install Node.js versions with the help of nvm.
Step 3: Using NVM
First of all, see what Node versions are available to install. To see available versions, type:
nvm ls-remoteNow, you can install any version listed in above output. You can also use aliases names like node for latest version, lts for latest LTS version, etc.
nvm install node ## Installing Latest version nvm install 20 ## Installing Node.js 20.X versionAfter installing you can verify what is installed with:
nvm ls
If you have installed multiple versions on your system, you can set any version as the default version any time. To set the node 20 as default version, simply use:
nvm alias default 20Similarly, you can install other versions like Node 12, 16, 18, and 21 versions and switch between easily.
Conclusion
That’s it. You have successfully installed and configured NVM on your macOS system. This tutorial also guides you through the basic uses of NVM, including installing Node.js versions, switching between different Node.js versions, and setting a specific version as the default. Once installed, developers can easily switch between versions as per their project requirements.
Từ khóa » H Nvm Mac
-
Node Version Manager - POSIX-compliant Bash Script To ... - GitHub
-
Installing Nvm On A New Mac To Support And Run Multiple ... - YouTube
-
Node Version Manager Install - Nvm Command Not Found
-
Install Nodejs With Nvm On OSX - Gary Woodfine
-
How To Install Nvm In Mac Code Example
-
How To Get Nvm On Mac Code Example
-
Unable To Install Nvm On Mac OSX - Documentation Appears To Be ...
-
The Best Way To Install Node.js, Npm And Yarn On Mac OSX
-
Solving Common Issues With Node-gyp - LogRocket Blog
-
Npm
-
Install Mongodb-client-encryption On Mac M1, Node 16
-
How To Install Node.js And NPM On Windows And Mac? - Radixweb
-
Getting Started As A Developer - Rush.js
-
Node Website Vs Homebrew Vs Using Nvm - CopyProgramming