How to install node. js in CentOS 7

Source: Internet
Author: User
Tags install node

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.

How to install node. js in CentOS 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.