Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Node.js Installation and Configuration

Node.js Installation and Configuration

This chapter introduces how to install Node.js on Windows, Linux, and macOS.

The download addresses for Node.js installation packages and source code are:https://nodejs.org/en/download。

- Install using the system's built-in package management tool (such as `apt`, `yum`, `brew`). - Automatically manage dependencies and updates, suitable for command-line users. - Official installation programs, suitable for Windows and macOS. - Graphical installation interface, including Node.js and npm. - Precompiled binary files; simply download and extract to use. - Suitable for users with a technical background who want to customize the installation location. - Node.js source code, which users must compile themselves. - Provides maximum flexibility, suitable for advanced users and developers who need custom configurations.

Node.js provides very detailed installation commands for different systems. You can choose the Node.js installation command script you need based on your platform.

The official website offers two versions:

It is recommended to choose the LTS version because it is more stable and has long-term technical support.

Download addresses for historical versions of Node.js:https://nodejs.org/dist/


Installing Node.js on Windows

You can install using the following two methods.

1. Windows Installer Package (.msi)

Installation steps:

1. Double-click the downloaded installer package, as shown below:

2. Click the Next button above, and the following interface will appear:

3. Check the option to accept the agreement and click the Next button:

4. The default installation directory of Node.js is "C:\Program Files\nodejs". You can change the directory and click the Next button:

5. Click Install to begin installing Node.js. You can also click Back to modify the previous configuration:

Installation process:

Click the Finish button to exit the installation wizard.

After installation, we can run the following command in the command line or Windows PowerShell to test:

node -v
npm -v

2. Windows Binary File (.exe) Installation

Click the "Prebuilt Binaries" option to download the binary file:

Installation Steps

Step 1: Double-click the downloaded installer package Node.exe, and the following interface will appear:

Clicking the Run button will open a command-line window:

After installation, we can run the following command in the command line or Windows PowerShell to test:

node -v
npm -v

If you get the output above, you have successfully installed Node.js.

Installing via the Command Line

We can also run the following command in PowerShell to install:

# 安装 fnm(快速 Node 管理器)
winget install Schniz.fnm

# Configure fnm environment to automatically use it on every directory change
fnm env --use-on-cd | Out-String | Invoke-Expression

# Download and install Node.js version 22
fnm use --install-if-missing 22

# Verify if the Node.js version in the environment is correct, the output should be `v22.11.0`
node -v # 应该输出 `v22.11.0`

# Verify the npm version in the environment, the output should be `10.9.0`
npm -v # 应该输出 `10.9.0`

Installing Node.js on Linux

1. Using the Official Installation Script

This example uses the fnm package manager as an illustration (nvm and others can also be used); the command is as follows:

# 安装 fnm(快速 Node 管理器)
curl -fsSL https://fnm.vercel.app/install | bash

# 激活 fnm
source ~/.bashrc

# Download and install Node.js
fnm use --install-if-missing 22

# Verify if the Node.js version in the environment is correct
node -v # 应该输出 `v22.11.0`

# Verify if the npm version in the environment is correct
npm -v # 应该输出 `10.9.0`

2. Directly Using a Precompiled Package

Click the "Prebuilt Binaries" option to download the binary file:

The Node official website has changed the Linux download to a precompiled version, so we can directly download and extract it for use:

# wget https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-arm64.tar.xz    // 下载
# tar xf  node-v22.11.0-linux-arm64.tar.xz       // Extract
# cd node-v22.11.0-linux-arm64/                  // Enter the extraction directory
# ./bin/node -v                                  // execute node command to view version

The bin directory of the extracted files contains commands such as node and npm; we can use the ln command to create symbolic links:

ln -s /usr/software/nodejs/bin/npm   /usr/local/bin/ 
ln -s /usr/software/nodejs/bin/node   /usr/local/bin/

3. Installing Node.js from Source

In the following section, we will introduce installing Node.js from source on Ubuntu Linux. Other Linux systems, such as CentOS, have similar installation steps.

Get the Node.js source code from GitHub:


$ sudo git clone https://github.com/nodejs/node.git
Cloning into 'node'...

Modify directory permissions:


$ sudo chmod -R 755 node

Use ./configure Create the build files and install:


$ cd node
$ sudo ./configure
$ sudo make
$ sudo make install

Check the node version:


$ node --version
v0.10.25

Installing on macOS

1. Using the Official Installation Script

This example uses the nvm package manager as an illustration (fnm and others can also be used); the command is as follows:

# 安装 nvm(Node 版本管理器)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# Download and install Node.js (may require terminal restart)
nvm install 22

# Verify if the Node.js version in the environment is correct
node -v # 应该输出 `v22.11.0`

# Verify if the npm version in the environment is correct
npm -v # 应该输出 `10.9.0`

2. Using Precompiled Installation Tools

For the downloaded .pkg file, double-click it to launch the installation wizard.

3. Directly Using a Precompiled Package

After downloading, extract the package and enter its bin directory, where you will find the precompiled node and npm, ready to use directly from the command line.