To install Node.js on macOS, you can use either the Node Version Manager (NVM) or the official Node.js installer. Here are instructions for both methods:
Install NVM: Open your terminal and run the following command to install NVM:
bashcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Close and Reopen Terminal: Close and reopen your terminal or run the following command to apply the changes without restarting:
bashsource ~/.bashrc
Install Node.js: After installing NVM, you can install the latest version of Node.js with the following command:
bashnvm install node
Use the Installed Version:
Once the installation is complete, you can use the installed Node.js version by default. If you need to switch between versions, you can use nvm use <version>
.
Download the Installer: Visit the official Node.js website at https://nodejs.org/, and click on the "LTS" (Long-Term Support) version. This version is recommended for most users.
Run the Installer:
Open the downloaded file (usually a .pkg
file), and follow the installation prompts.
Verify Installation: After the installation is complete, open a terminal and run the following commands to verify that Node.js and npm (Node Package Manager) are installed:
bashnode -v
npm -v
This should display the installed versions of Node.js and npm.
That's it! You have successfully installed Node.js on your macOS system. Choose the method that suits your preferences or requirements.