Home  >  Article  >  Web Front-end  >  How to install Node.js on Mac

How to install Node.js on Mac

PHPz
PHPzOriginal
2023-04-26 09:09:1616932browse

Node.js is a JavaScript runtime environment based on the Chrome V8 engine. It enables JavaScript to run on the server side, which allows developers to write server-side applications in JavaScript. The emergence of Node.js not only unifies the development languages ​​of the front-end and back-end, but also greatly improves development efficiency.

This article will introduce how to install Node.js on Mac system. The installation of Node.js is roughly divided into the following two methods:

  1. Download the installation package through the official website
  2. Install NVM through the command line

Method 1: Download the installation package through the official website

  1. Open the official website of Node.js and find the download page: https:// nodejs.org/en/download/
  2. Click the "macOS Installer" button to download the installation package.

How to install Node.js on Mac

  1. After the download is completed, you will see a file named "node-vXX.XX.X.pkg" (XX. XX.X is the version number) installation package.
  2. Double-click the installation package and follow the steps of the installation wizard.

How to install Node.js on Mac

  1. After the installation is complete, enter the following command in the terminal:
node -v

If the version number appears, the installation is successful. .

Method 2: Install NVM through the command line

  1. First, enter the following command in the terminal to install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. After the installation is successful, Enter the following command to install NVM:
brew install nvm
  1. After the installation is complete, enter the following command in the terminal to configure NVM:
mkdir ~/.nvm
nano ~/.bash_profile
  1. Open "bash_profile" Add the following code to the file:
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Save and exit the file.

How to install Node.js on Mac

  1. Enter the following command in the terminal to make the modified configuration take effect:
source ~/.bash_profile
  1. Enter the following command to view the latest Node .js version number:
nvm ls-remote
  1. Enter the following command in the terminal to install Node.js:
nvm install 版本号

For example, install the latest version of Node.js:

nvm install node
  1. After the installation is complete, enter the following command in the terminal to verify whether Node.js is installed successfully:
node -v

If the version number appears, it means the installation is successful.

So far, the two methods of installing Node.js on Mac systems have been introduced. If you want to uninstall Node.js, you can enter the following command in the terminal:

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/man1/node.1.gz}

Note: Before executing, please make sure to back up the files that need to be retained.

The above is the detailed content of How to install Node.js on Mac. 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