Configure the node. js environment in Centos7

Source: Internet
Author: User

Configure the node. js environment in Centos7

1. software environment:

Centos7, VMware 10.0, NodeJSv0.10.24

2. Installation Process

1. administrator and root permissions are required during installation. You can run the following command.

[Sharing @ localhost ~] $ Su root
After you press enter, the following message is displayed:

Password:
Enter the password you set. It is not displayed on the terminal during the input process, but it has already been entered. The input is as follows:

[Root @ localhost sharing] #

2. First confirm that nodejs compilation and dependency software are available. If not, run the following command to install nodejs.

[Root @ localhost sharing] # yum-y install gcc-c ++ openssl-devel
3. Download and decompress the node. js source code package.

[Root @ localhost sharing] # wgethttp: // nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
[Root @ localhost sharing] # tar zxvf node-v0.10.24.tar.gz
[Root @ localhost sharing] # cd node-v0.10.24

4. Configure, compile, and install.

[Root @ localhost node-v0.10.24] #./configure -- prefix =/usr/local/node

[Root @ localhost node-v0.10.24] # make & make install

5. Configure the Node Environment

[Root @ localhost node-v0.10.24] # vim/etc/profile too many

Use vim for the first time... After vim enters the profile, we will see the content in the profile file, press the keyboard I to enter the editing mode, and then write the following content at the end of the text.

Export NODE_HOME =/usr/local/node
Export PATH = $ NODE_HOME/bin: $ PATH
Export NODE_PATH = $ NODE_HOME/lib/node_modules: $ PATH

After the input, Press Esc to exit the editing mode, and then press: wq to exit and save.

Then enter the following command to take effect.

[Root @ localhost node-v0.10.24] # source/etc/profile

6. Test whether it is successful

[Root @ localhost node-v0.10.24] # node-v

V0.10.24
The NodeJS version number indicates that the installation is successful.

7 test example

Enter the following code to create a new text:

Var http = require ('http ');
Http. createServer (function (req, res ){
Res. writeHead (200, {'content-type': 'text/plain '});
Res. end ('Hello Node. js \ n ');
}). Listen (8421, "127.0.0.1 ");
Console. log ('server running athttp: // 127.0.0.1: 8421 /');

Save it as test. js, enter node test. js on the terminal, and open http: // 127.0.0.1: 8421/in the browser.

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.