How to install Node. JS on Ubuntu _ node. js

Source: Internet
Author: User
Tags line editor
This article describes how to install Node on Ubuntu. JS tutorial, Node. JS's high-performance V8 interpreter running and asynchronous mechanism bring great popularity to it. If you need them, you can refer to Node. js uses WebSocket-based push technology for real-time Web applications. What kind of revolution does this mean? Well, after more than 20 years of stateless Interaction Based on the stateless request-return mechanism, we finally have a real-time, bidirectional connection web application, both the client and the server can initiate communications and exchange data freely. In contrast to the traditional web response mode, the Client Always actively initiates communications and the server passively returns responses. In addition, these are based on open Web Components (HTML, CSS, and JS) running on the standard port 80 ).

It may be said that we have been using Flash and Java applets for many years-but in fact, these methods only use the network to transmit data to the sandbox environment on the client. They are all isolated and often operate non-standard ports that require additional permissions.

With its unique advantages, Node. js has now played a key role in the products of many famous companies.

The main idea of Node. js is to use non-blocking, event-driven I/O operations to maintain lightweight and efficient processing of cross-platform (distributed SS distributed devices) data-intensive real-time applications. This sounds a bit difficult.

Its true meaning is that Node. js is not a silver bullet-level platform that will take the lead in the world of Web development. On the contrary, it is a platform that meets special requirements. You certainly do not want to use Node. js for CPU-intensive operations. In fact, using it for heavy computing means abandoning almost all the advantages of Node. The real highlight of Node is the construction of high-performance, highly scalable Internet applications-because it can handle massive and high-throughput concurrent connections.

Basic System Installation
Node can run perfectly on Linux, Macintosh, and Solaris systems. Ubuntu is suitable for linux releases. This is why we try to install Node. js on ubuntu 15.04. Of course, we can also install Node. js through the same steps on ubuntu 14.04.

1) system resources
The basic system resources required by Node. js depend on your architecture requirements. In this tutorial, we will perform the installation on a server with 1 GB memory, 1 GHz processor, and 10 GB disk space. The installation is minimal and no Web server or database server is required.

2) system updates
Before installing Node. js, we recommend that you update the system to the latest patch and upgrade package. Therefore, log on to the system and run the following command with the superuser:

# apt-get update


3) install Dependencies
Node. js only requires some basic system and software functions on your server, such as 'make', 'gcc ', and 'wget. If you have not installed them, run the following command to install them:

# apt-get install python gcc make g++ wget


Download Node JS v4.0.0 of the latest version.
Visit the Node JS Download Page to Download the source code.

Copy the link of the latest source code and download it with wget. The command is as follows:

# wget https://nodejs.org/download/rc/v4.0.0-rc.1/node-v4.0.0-rc.1.tar.gz


After the download is complete, run the tar command to decompress the package:

# tar -zxvf node-v4.0.0-rc.1.tar.gz



Install Node JS v4.0.0
Now you can use the downloaded source code to compile Node. js. Before compilation, you need to switch to the decompressed directory of the source code on ubuntu server and run the configure script to configure the source code.

root@ubuntu-15:~/node-v4.0.0-rc.1# ./configure



Run the 'Make install' command to compile and install Node. js:

root@ubuntu-15:~/node-v4.0.0-rc.1# make install


The make command will take several minutes to complete the compilation, and wait quietly for a while.

Verify Node. js Installation
Once the compilation task is completed, we can start to verify whether the installation is OK. Run the following command to confirm the Node. js version.

root@ubuntu-15:~# node -v


V4.0.0-pre
The node running without parameters in the command line enters the REPL (Read-Eval-Print-Loop, Read-execute-output-Loop) mode, it has a simplified emacs Line Editor, through which you can run JS interactively and view the running results.

Compile a test program
We can also write a very simple terminal program to test whether the installation is successful and works properly. To do this, we will create a "test. js" file, which contains the following code:

root@ubuntu-15:~# vim test.jsvar util = require("util");console.log("Hello! This is a Node Test Program");:wq!


Now, in order to run the above program, run the following command in the command line.

root@ubuntu-15:~# node test.js



Running the above program in an environment where Node JS is successfully installed will get the output shown on the screen. This program loads the class "util" to the variable "util, then run the terminal task with the object "util", console. the log command is similar to the cout in C ++.

Conclusion
That's all. If you are just using Node. js to develop applications, I hope this article will show you about Node. js by installing and running Node. js on ubuntu. Finally, we can expect significant performance improvement from Node JS v4.0.0.

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.