I've been interested in learning more about node. JS recently. This is a server-side programming of the Java platform that allows developers to write Java code on the server, and many CentOS users are trying to learn the language's development environment. This is exactly what I want to do with this tutorial.
First, make sure you have CentOS 7. Because it is the only version I am using, of course there is no absolute guarantee that this guide can be used in other versions as well.
Installing node. js from the source
First we need to install node. js from the source. I really like to install software from the source code. Open a new Terminal tab on your CentOS 7 machine and run the following command to download the installation files you need to use.
wget http://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz
You can see from the above commands how we use wget to operate.
Then extract the tar file as shown below.
Tar xvf node-v0.12.0.tar.gz
Then use the following command to change the working directory node.
CD node-v*
Before compiling our code, we need to install some packages on the CentOS machine so that we can compile. So in the terminal you opened, enter the following.
sudo yum install gcc gcc-c++
Wait for these packages to be installed and run, to be configured and compiled under commands.
./configure
Make
The above will take some time to complete, don't worry because compiling will take a while. Then use the following command to install node. js on your system.
sudo make install
Once the installation is complete, you are ready to start using node. js. And to make sure that the installed version is correct, you can use the following command to check.
Node--version
When I run the above command, I get the following information.
v0.12.0
How to install node. js from the Epel library
Another effective and simple way to install node. JS is from the official library. This also ensures that you have access to the Epel library, which you can run by running the following command.
sudo yum install epel-release
You can now install node. js with the Yum command.
sudo yum install Nodejs
Because I need to manage the node packages during development, I will also install the new public managed Package Manager, using the following commands.
sudo yum install NPM
Write our first node. JS program.
It's easy to write the Hello World app in node. js! Simpler than Python. All you need to do is write the following code in a file and save it as something.js.
Console.log ("Hello World");
Save the Hello.js we just created. Then in order to run it, we need to use the following command.
Node Hello.js
Now open your text editor hello.js and add the following code. You can copy and paste but I strongly recommend that you personally enter it because this is a good opportunity for you to be familiar with node. 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 ');
Use the following command to run the application.
Node Hello.js
Now, what do you see? This example is a bit complicated for beginners, but it is not difficult to understand. In your browser access http://www.localhost:8000/When the above code, it will show "Hello World".
If you want to learn more about node. js, please visit nodejs.org.
Conclusion
If you find the right boot and follow the instructions very carefully, it is not difficult to believe that node. js is installed on the CentOS operating system. I hope this tutorial will help you install it.
Dashan want to know the author please visit the Linux commune
Linux commune original translation channel:http://www.linuxidc.com/topicnews.aspx?tid=15
Here's what you might also like :
Setting up node. JS development environment under Ubuntu 14.04 http://www.linuxidc.com/Linux/2014-12/110983.htm
UBUNRU 12.04 installation configuration for the node. JS Development Environment Http://www.linuxidc.com/Linux/2014-05/101418.htm
node. js Getting started [pdf+ related code] http://www.linuxidc.com/Linux/2013-06/85462.htm
node. JS Development Guide HD PDF Chinese + source http://www.linuxidc.com/Linux/2014-09/106494.htm
Node. JS Introduction Development Guide Chinese version http://www.linuxidc.com/Linux/2012-11/73363.htm
node. js Installation and Configuration http://www.linuxidc.com/Linux/2013-05/84836.htm
Ubuntu compiler installs node. js http://www.linuxidc.com/Linux/2013-10/91321.htm
detailed description of node. JS : Please click here
node. js : Please click here.
This article permanently updates the link address : http://www.linuxidc.com/Linux/2015-02/113554.htm
How to install node. js in CentOS 7