Let’s first take a look at how to compile and install from the source code
1. Install the dependency package
[root@1c3b4a5a8f31 ~]# yum -y install gcc gcc-c++ openssl-devel
2. Download the source code package
[root@1c3b4a5a8f31 ~]# wget http://www.nodejs.org/dist/latest/node-v0.12.5.tar.gz [root@1c3b4a5a8f31 ~]# tar -zxvf node-v0.12.5.tar.gz [root@1c3b4a5a8f31 ~]# cd node-v0.12.5
3. Configure, compile and install
[root@1c3b4a5a8f31 ~]# ./configure --prefix=/usr/local/node [root@1c3b4a5a8f31 ~]# make && make install
4. Configure nodejs environment
[root@1c3b4a5a8f31 ~]# vim /etc/profile #set nodejs env export NODE_HOME=/usr/local/node export PATH=$NODE_HOME/bin:$PATH export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH [root@1c3b4a5a8f31 ~]# source /etc/profile #重启生效
5. Test whether the installation is successful
[root@1c3b4a5a8f31 ~]# node -v v0.12.5 [root@1c3b4a5a8f31 ~]# npm -v 2.11.2
Let’s see how to use yum Installation
Install node.js
Log in to Centos
Terminal login $ ssh root@192.168.0.23 The IP can be the LAN or public IP.
Download node
According to your system, find the version you need to download on the official website https://nodejs.org/en/download/. For example, I chose Linux Binaries (x86/x64) 64bit. Right-click to copy the connection address of the version you need, and download the nodejs installation compressed package through the command.
$ wget https://nodejs.org/dist/v4.4.4/node-v4.4.4-linux-x64.tar.xz
If your wget command does not exist, you can install the download tool through the yum install wget command wget. If you have the smallest version of centos, you need to install yum -y install gcc make gcc-c++ openssl-devel wget
Unzip and install
# 没有用到`gzip`压缩去掉`z`参数 $ sudo tar --strip-components 1 -xzvf node-v* -C /usr/local
Check the installation
You can check whether the installation is successful! Generally, the installation will report an error message. If no error message is reported, you can test whether the installation is successful by calling the node command!
node -v # 会输出版本信息 # v6.9.1 npm -v # 会输出版本信息 # 3.10.8
Finally let’s take a look at installing through NPM
Step1.
Enter http://nodejs.org/dist/ to download the required version of node.js
(for example, the latest Version link http://nodejs.org/dist/v0.12.7/, download node-v0.12.7-linux-x64.tar.gz)
Step2.
Unzip: tar –xf node-v0.12.7 -linux-x64.tar.gz
Configure environment variables (add bin under node to environment variables)
Step3. (Use express application generator)
Execute: npm install express-generator –g
After completion, the following content will be prompted.
Step4.
Follow the prompts and execute the command cd test
npm install
Then execute npm start.
You can open the browser and enter localhost: 3000 in the address bar