Easy Tutorial
❮ Nodejs Router Nodejs Tutorial ❯

Node.js Installation and Configuration

This section will guide you through the installation of Node.js on Windows and Linux.

This installation tutorial uses Node.js v4.4.3 LTS (Long-Term Support) as an example.

Node.js installation packages and source code can be downloaded from: https://nodejs.org/zh-cn/download/.

You can choose the appropriate Node.js installation package based on your platform.

Node.js historical versions can be downloaded from: https://nodejs.org/dist/

Note: Installing Node.js on Linux requires Python 2.6 or 2.7. It is not recommended to install Python 3.0 or later.


Installing Node.js on Windows

You can install Node.js using one of the following methods:

1. Windows Installer (.msi)

This example uses version v0.10.26, but other versions are similar.

Installation steps:

Step 1: Double-click the downloaded installer v0.10.26, as shown below:

Step 2: Click "Run" and the following interface will appear:

Step 3: Check the "Accept the Agreement" option and click "Next":

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

Step 5: Click the tree icon to select your desired installation mode, then click "Next":

Step 6: Click "Install" to start the installation of Node.js. You can also click "Back" to modify previous configurations, then click "Next":

Installation process:

Click "Finish" to exit the installation wizard.

Check if the PATH environment variable includes Node.js. Click "Start" => "Run" => type "cmd" => type "path". The output should be:

PATH=C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
c:\python32\python;C:\MinGW\bin;C:\Program Files\GTK2-Runtime\lib;
C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\nodejs\;
C:\Users\rg\AppData\Roaming\npm

We can see that "C:\Program Files\nodejs\" is included in the environment variables.

Check the Node.js version.

2. Windows Binary (.exe) Installation

32-bit installer download link: http://nodejs.org/dist/v0.10.26/node.exe

64-bit installer download link: http://nodejs.org/dist/v0.10.26/x64/node.exe

Installation Steps

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

Click "Run" and a command line window will appear:

Version Testing

Navigate to the directory where node.exe is located:

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


Installing Node.js on Linux

Using a Precompiled Package

Node's official website has changed the Linux download version to a precompiled package, which we can download, extract, and use directly:

# wget https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.xz    // Download
# tar xf node-v10.9.0-linux-x64.tar.xz       // Extract
# cd node-v10.9.0-linux-x64/                  // Navigate to the extracted directory
# ./bin/node -v                               // Execute the node command to check the version
v10.9.0

The bin directory of the extracted files contains commands like node and npm. We can use the ln command to set symbolic links:


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


### Installing Node.js from Source on Ubuntu

The following section will guide you through installing Node.js from source on Ubuntu Linux. Other Linux systems, such as CentOS, follow similar installation steps.

Clone the Node.js source code from Github:

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


Change directory permissions:

$ sudo chmod -R 755 node


Create the build file using **./configure** and install:

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


Check the node version:

$ node --version v0.10.25


### Installing Node.js using apt-get on Ubuntu

Use the following command format:

sudo apt-get install nodejs sudo apt-get install npm


### Installing Node.js from Source on CentOS

1. Download the source code. You need to download the latest Node.js version from [https://nodejs.org/en/download/](https://nodejs.org/en/download/). This example uses v0.10.24:

cd /usr/local/src/ wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz


2. Extract the source code:

tar zxvf node-v0.10.24.tar.gz


3. Compile and install:

cd node-v0.10.24 ./configure --prefix=/usr/local/node/0.10.24 make make install


4. Configure NODE_HOME and edit the environment variables:

vim /etc/profile


Set the Node.js environment variables. Add the following content above the existing lines:

set for nodejs

export NODE_HOME=/usr/local/node/0.10.24 export PATH=$NODE_HOME/bin:$PATH


Save and exit with :wq, then compile /etc/profile to apply the configuration:

source /etc/profile


Verify the installation and configuration:

node -v


Output v0.10.24 indicates successful configuration.

The npm module installation path is:

/usr/local/node/0.10.24/lib/node_modules/


**Note:** The Node.js official website provides precompiled Linux binary packages that you can download and use directly.

---

## Installing on Mac OS

- 1. Download the pkg installer from the [official download website](https://nodejs.org/en/download/) and install it by clicking on it.

- 2. Install using the brew command:

brew install node ```

❮ Nodejs Router Nodejs Tutorial ❯