method One: Install Node.js from Epel library
An effective and simple way to install node.js is to download the installation from the official library, first ensuring that you have access to the Epel library, and you can install it by running the following command.
sudo yum install epel-release
You can now install node.js using the Yum command.
sudo yum install Nodejs
Because I need to manage the node bundle during the development process, I will also install the new publicly managed Package manager, using the following command.
(Note: Since the new Nodejs has already integrated NPM, this step can be ignored.) )
sudo yum install NPM
Check:
# node--version
v6.12.2
# npm--version
3.10.10
As you can see, the version is older when installed in this way. method Two: Download the source code, compile the installation
Go to the official website to find the latest or the node.js version that you want, copy the URL, and use wget to download in the CentOS.
wget https://nodejs.org/dist/v8.9.4/node-v8.9.4.tar.gz
Extract:
Tar zxvf node-v8.9.4.tar.gz
Enter directory:
CD node-v8.9.4
Configuration:
./configure
Compile:
Make
Installation:
sudo make install
Check:
# node--version
v8.9.4
# npm--version
5.6.0
Wow. The version is not new a lot. Test
Write a Hello world test.
Vim Something.js
Input:
Console.log ("Hello World");
Run:
# node Something.js
Hello World
What the. It's too easy. Amount of ... One more.
# cat Hello.js
var http = require (' http ');
Http.createserver (function (request, response) {
response.writehead ({' Content-type ': ' Text/plain '});
Response.End (' Hello world\n ');
Listen (8080);
Console.log (' Server started ');
Execute # Node Hello.js, and then open the browser, enter: ip:8080
Haha, you have completed a web development, is not very excited about it.
Reference article: http://www.linuxidc.com/Linux/2015-02/113554.htm