Node NVM Installation - Mac
01 Prerequisite - Install XCode tools #
Starting with MacOS 10.9, XCode command line tools must be installed, prior to installing NVM.
1a XCode Developer tools only #
Recommended for most! If you don't want to download and install the full XCode, you can install just the developer tools (much smaller than the full install) by doing the following:
- Open Spotlight with Command + spacebar.
- Type "Terminal", press Enter.
- Type
xcode-select -p
, press Enter. If this returns something like/Library/Developer/CommandLineTools
then you already have the tools and you can move to step 02 - Otherwise type
xcode-select --install
, press Enter and follow the prompts.
1b XCode Full Install (optional) #
If you think you will ever want to build native MacOs or IOS apps, download and install XCode. Apple’s XCode development software is used to build Mac and iOS apps, but it also includes the tools you need to compile software for use on your Mac. XCode is free and you can find it in the Apple App Store but it is quite large (Over 3.5G!) After you install it, open it at least once to accept the Terms. Step 02 will not work, after doing the full Xcode install, unless you have accepted the terms.
02 - NVM GitHub Installation #
- Go to https://github.com/nvm-sh/nvm.
- Scroll down to the "Installing and Updating" heading.
- Locate the curl Install and update script and click the copy icon on the right. (Should look something like this:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
) - Open the terminal (Command + spacebar, type "terminal", press Enter).
- Paste the script into the terminal, press Enter.
- Expect the installation process to take ~ 15 seconds, depending on your Internet
connection. - When the process is complete, close and reopen the terminal.
- Type
nvm -V
, press Enter. A long list of nvm commands will appear. This means nvm is installed and ready to be used. - If an error appears, return to the github location and scroll down to the
"Troubleshooting on macOS" section and see if you can identify your error and how to deal with it.
03 – Install the Long Term Support (LTS) version of NodeJS #
- In the terminal, type
nvm install --lts
, press Enter. - A message should appear indicating the version number of node being downloaded.
- When done, a message will appear like "Now using node v20.11.0 (npm v10.2.4)".
04 – Installing and using a different Node version #
If you need to download and use a different version of Nodejs, do the following:
- Open the terminal.
- Type "nvm install version number" (e.g.
nvm install 19
), press Enter. - When done, you will see a message like "Now using node v19.9.0 (npm v9.6.3)".
04a – List all versions of Node that are available to install #
- Open the terminal.
- Type
nvm ls-remote
, press Enter. - The list will appear.
- Repeat the installation steps, using the version number as needed.
05 - List Node Versions Installed on your computer #
- Open the terminal as an administrator.
- Type
nvm ls
, press Enter. - A list of all installed versions of Node, that NVM is tracking, appears.
- To see the current version of Node, type
node -v
, press Enter.
06 - Switch Node Versions #
If needing a different Node version for another project, just switch after opening the project.
- In VS Code, or any tool, open the project.
- Open a terminal and type, "nvm use version number" (appropriate to your required
node version), press "Enter". - You should now be switched to that version of Node.