search
HomeSystem TutorialMACHow to install NVM on Mac for managing Node.js

Efficiently manage multiple Node.js versions: NVM installation guide for Mac system

How to install NVM on Mac for managing Node.js

Managing multiple Node.js versions simultaneously, especially when one project requires version 14 and the other requires version 16, it may feel like walking a tightrope. Believe me, I have a deep understanding - I once stayed up late to debug error messages for the project's requirements for the Node.js version. At this time, NVM (Node version manager) comes in handy.

Whether you are a developer running legacy projects, a developer trying the latest features, or a beginner who is learning Node.js for the first time, NVM ensures your productivity. You can think of it as your Node.js "time machine" that allows you to switch freely between different versions.

If you have similar problems, please let me take you to install NVM on your Mac system step by step. I will break all the steps down in great detail to make it easy for you to complete the installation.

How to install NVM on Mac for managing Node.js

Preparation before installing NVM

Before installing NVM, let's quickly review some preparations to ensure the installation process goes smoothly.

You need:

  • Terminal: This is the preferred tool for running commands. In the latest macOS Sequoia and older versions, you can open the terminal by pressing Command Space, entering "Terminal", and then pressing Return.
  • State Basics: Don't be scared by the word "basic". If you are able to enter a command and press Return, you are ready. I will guide you through everything step by step.
  • Homebrew or MacPorts (optional): These are package managers for installing software such as NVM. You can think of them as an app store for your terminal. While optional in this guide, package managers like Homebrew can save a lot of time by automating downloads, installations, and updates. If you don't have a package manager installed, installing Homebrew on your Mac is a great option – it's simple, reliable, and much easier than manually downloading it.

Also, check out how to uninstall Node.js on your Mac.

How to install NVM on Mac for managing Node.js

Install NVM using curl or wget

The most popular and straightforward way to install NVM is to use curl (a common tool already installed on most Macs) or wget (another tool for downloading files). This is the way I tried first, as it looks fast and I'm eager to fix the Node.js issue in my project.

Note: curl and wget? Just use any available tools. curl is pre-installed on macOS, but you can install wget via Homebrew (brew install wget) if needed. If you are not sure which shell you are using, run echo $SHELL. Starting with macOS Catalina, Zsh is the default shell, so most users will edit ~/.zshrc.

Start from the terminal

Before we understand the installation process in depth, let's first understand the operation process of the terminal, especially for new users of macOS Sequoia. This is not difficult.

Operation steps:

  1. Press Command Space and enter "Terminal" to open it.
  2. Installing NVM:
  • If you use curl, enter curl -o- https://raw.githubusercontent.... | bash
  • If you use wget, enter wget -qO- https://raw.githubusercontent.... | bash
  1. Add the following lines to your shell configuration file to ensure that NVM loads every time you open the terminal:
  • For Zsh (the default value for newer macOS versions), enter nano ~/.zshrc
  • For Bash (used in older macOS versions), enter nano ~/.bash_profile
  1. Add the following lines to the file:
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
  2. Activate the update configuration file and enter source ~/.zshrc (If you are using Bash, replace ~/.zshrc with ~/.bash_profile).
  3. Check that NVM is installed correctly, enter nvm --version.

How to install NVM on Mac for managing Node.js

Congratulations if you see the version number! You have successfully installed NVM.

Personal Experience: When I first installed NVM, I encountered a problem: the Xcode command line tool is missing. Quick solution: xcode-select --install. After running the curl command, adding NVM to my shell configuration file, and applying the changes with source ~/.zshrc, everything worked fine.

How to install NVM on Mac for managing Node.js

Install NVM using Homebrew

If you like to save time and simplify operations, Homebrew is your best choice when installing NVM. It's like the Swiss Army Knife of macOS tools - simple, reliable, and can handle all the tedious things for you. If you want to escape at the thought of copying messy scripts, Homebrew is your new best partner. It can complete tasks quickly and give you more valuable time.

I fell in love with it the first time I used Homebrew. It feels like finding a cheat code for your Mac. Trust me, once you try it, you’ll want to know how you survived without it before.

The following is how to install NVM using Homebrew:

  1. Open the terminal and install Homebrew (if you have not installed it already), enter /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)".
  2. Use Homebrew to install NVM, enter brew install nvm.
  3. Create an NVM directory and load NVM, enter mkdir ~/.nvm export NVM_DIR="$HOME/.nvm" . "$(brew --prefix nvm)/nvm.sh".
  4. Add the following lines to your shell configuration file to ensure that NVM loads every time you open the terminal:
  • For Zsh (the default value for newer macOS versions), enter nano ~/.zshrc
  • For Bash (used in older macOS versions), enter nano ~/.bash_profile
  1. Add the following lines to the file:
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
  2. Activate the update configuration file and enter source ~/.zshrc (If you are using Bash, replace ~/.zshrc with ~/.bash_profile).
  3. Check that NVM is installed correctly, enter nvm --version.

How to install NVM on Mac for managing Node.js

If the version number appears, congratulations - you have successfully installed NVM using Homebrew!

Install NVM using MacPorts

If you are familiar with MacPorts, it is also a good choice for installing NVM. It keeps things simple and relieves the pressure to manage software on your Mac. I've used it before on older macOS versions and while it's not the most beautiful tool, it's reliable and actually helps you with what you need to do. Sometimes, this is the most important thing.

The following is how to install NVM using MacPorts:

  1. Install and open MacPorts using a compatible version of macOS.
  2. Open the terminal and enter sudo port install nvm to install NVM through MacPorts.
  3. Load NVM by updating your shell configuration file. Add the following command to ~/.zshrc or ~/.bash_profile:
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
  4. Apply changes by running source ~/.zshrc.
  5. Use nvm --version to verify the installation.

How to install NVM on Mac for managing Node.js

If you see the version number, then you can start!

Install and manage multiple Node.js versions using NVM

This is where NVM really comes into play. I remember working on two projects at the same time (this is my basic situation) – one requires Node.js 14 for stability and the other requires Node.js 18 for the latest features. Without NVM, switching the version would be a nightmare and requires uninstalling, reinstalling, and praying that there will be no problems or anything missing during the process. Once I discovered NVM, it felt like I had taken off the burden on my shoulders.

The following is how to make Node.js version management easy:

  • Install a specific version. Suppose you need Node.js 14. Just run nvm install 14 and NVM will download and set it up. It's as simple as grabbing a cup of coffee from your favorite cafe – no drama.
  • Switch between versions. Need to switch to Node.js 16? Just run nvm use 16 and you're done. I use this feature frequently when testing updates in a sandbox environment.
  • Set the default version. Tired of typing commands every time? Use nvm alias default 14 to set Node.js 14 as your preferred version. This way, it will load automatically when you open the terminal – perfect for long-term projects.

With NVM, you can quickly test, debug and run projects in different Node.js environments without any effort. I've saved countless hours (and avoided a lot of headaches) by letting NVM handle version management for me.

How to install NVM on Mac: Summary

It is much easier to manage Node.js on macOS using NVM. Whether you install it using curl, Homebrew, or MacPorts, the process is very simple and flexible. After installation, switching between Node.js versions takes only a few seconds, avoiding compatibility issues.

How to install NVM on Mac for managing Node.js

FAQ

How to know if NVM is installed on my Mac?

To check if NVM is installed on your Mac, run nvm --version in your terminal. If the version number is displayed, it means that NVM is installed.

How to install NVM on Zsh?

Install NVM on Zsh:

  1. Run the following command in the terminal to install NVM: curl -o- https://raw.githubusercontent.... | bash.
  2. Open your Zsh configuration file: nano ~/.zshrc.
  3. Add the following lines at the end of the file:
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
  4. Reload your Zsh configuration by running source ~/.zshrc.
  5. Can confirm that NVM is installed and works properly by entering nvm --version.

How to set the path to NVM on Mac?

To set up the path to NVM on your Mac, add export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" to your shell configuration file and run source ~/.zshrc in your terminal.

Note that I cannot copy the command in the output in full since the full curl or wget command link is omitted from the original text. Please find the correct installation command link by yourself.

The above is the detailed content of How to install NVM on Mac for managing Node.js. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to convert Word to jpg on Mac – SetappHow to convert Word to jpg on Mac – SetappApr 18, 2025 am 10:23 AM

Convert Word documents to JPEG images: Detailed explanation of various methods When working with text documents (articles, reports, papers, etc.) on a Mac, we usually use Microsoft Word. Microsoft Word has been available on Mac since Classic Mac OS in 1985 and is becoming increasingly popular. Today, most users use Microsoft Word as part of the Microsoft Office 365 suite. When it comes to functionality, Microsoft Word surpasses any competitor – it offers endless possibilities for writing and formatting documents. Sometimes you need to convert the document to various formats so that

How To Open 7z Files Instantly – SetappHow To Open 7z Files Instantly – SetappApr 18, 2025 am 10:22 AM

Efficient compression and decompression 7z file: Mac user guide Since the early days of software and computers, people have been working hard to reduce the size of files. Initially, this was because of the high storage costs, and a few megabytes of hard drives cost hundreds of dollars! Even today, when SSDs and cloud storage can be measured in terabytes, we are not too keen on using and paying more than we need. If you think about all the photos and videos we store, sometimes we have to pay a lot for it. Additionally, we want the files to work properly when transferred via email and the folders are kept intact. Have you ever encountered a situation where you email a folder but it is empty when it arrives? The solution to all these problems is archive

How to flip a picture on iPhoneHow to flip a picture on iPhoneApr 18, 2025 am 10:04 AM

iPhone selfie mirroring problem and solutions We are all used to being in the mirror, so we prefer the images in the mirror. When using the iPhone selfie camera, the screen shows the image flipped left and right. But after taking a photo, you will find that the photos in the photo library are different from what you saw before the photo shoot, which is frustrating! Want to fix the flipped selfie to make it exactly the same as what you see in the viewfinder? Let's see how to reverse the photos on your iPhone while taking a selfie. I think... I need to... Flip the photos Open the Photos app, select the photo, click Edit, use the Crop tool, and then click the Flip icon. Mirrored selfies on iOS 14 and later Go to "Set

This Apple ID Is Not Active: Why Does It Mean & How to Fix It?This Apple ID Is Not Active: Why Does It Mean & How to Fix It?Apr 18, 2025 am 09:58 AM

Encountering the "This Apple ID is not active" error on your Mac? This usually means Apple has temporarily locked your account for security reasons due to unusual login attempts. Don't panic; this guide provides troubleshooting steps to r

What to do if MacBook won't boot past Apple logoWhat to do if MacBook won't boot past Apple logoApr 18, 2025 am 09:40 AM

urgent! Mac stuck in Apple Logo interface? Solve the problem within 10 minutes and catch up with important meetings! I have experienced this dilemma: an important Zoom meeting is about to begin, but my MacBook Pro is stuck in the Apple logo interface and can only anxiously ask the team for help on Slack. Fortunately, the problem was finally resolved in less than 10 minutes and I successfully caught up with the meeting. Hope this article helps you avoid similar hassles. Let's get started! Setapp helps you solve Mac problems easily If there is any problem with your Mac, Setapp can help you solve it. It provides an ever-expanding collection of troubleshooting applications. Free trial safe and reliable iMac, Mac Mini, Ma

How to stop Google Chrome pop ups on Mac – SetappHow to stop Google Chrome pop ups on Mac – SetappApr 18, 2025 am 09:32 AM

The internet's become a much busier place. What started with simple banner ads has exploded into intrusive pop-ups, aggressive newsletter sign-ups, and even malicious scripts. This article shows you how to reclaim your browsing experience by effect

How to extract images from PDF (without losing quality)How to extract images from PDF (without losing quality)Apr 18, 2025 am 09:29 AM

After learning these few ways to save images from PDFs, you’ll never have to deal with blurry photos and winding paths of image extraction. Some methods are pretty limited, but others let you extract them easily. Extract all images from the PDF

Achieve total fan speed control on Mac: Ultimate guideAchieve total fan speed control on Mac: Ultimate guideApr 18, 2025 am 09:20 AM

Mac fans are too noisy? Master these skills and control them easily! Mac fans are usually unknown until they make an annoying noise. In fact, it is crucial in maintaining the internal temperature of the Mac and preventing overheating. When a Mac handles a large number of high-load processes at the same time (such as image post-processing), the chip, hard disk and graphics card will heat up. If the heat is not dissipated in time, it may cause irreparable damage. The fan cools the hardware by improving air circulation, keeps temperature stable and ensures maximum performance output. But sometimes, the fan can get out of control, either overrunning when the Mac is not hot or running too slowly when it is overheated. At this point, you may need to manually control the fan speed and even learn how to turn off your Mac fan when you don't need it. Note:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool