How to Install Node JS in Ubuntu 22.04

Node.js adopts WebSocket-based push technology in real-time web applications. What does this mean for performance? Well, after more than 20 years of stateless request-response interaction based on the stateless mechanism, we finally have real-time, bidirectional web applications where both the client and server can initiate communication and exchange data freely.

This is in stark contrast to traditional web response patterns, where the client always initiates communication and the server passively responds. In addition, these are all open web components (HTML, CSS, and JS) that run on the standard port 80.

Some people may say that we have been using Flash and Java Applets for many years – but in reality, these are just sandboxed environments that use the network to pass data to the client. They are all isolated and often operate on non-standard ports that require additional privileges.

With its unique advantages, Node.js now plays a critical role in many well-known companies' products.

The main idea behind Node.js is to use non-blocking, event-driven I/O operations to keep lightweight and efficient when processing cross-platform (across distributed devices) data-intensive real-time applications. This may sound a bit convoluted.

The real meaning of this is that Node.js is not a silver bullet platform that will soon dominate the world of web development. Instead, it is a platform that satisfies special needs. You certainly wouldn't want to use Node.js for CPU-intensive operations. In fact, using it for heavy calculations is almost tantamount to abandoning Node's advantages. The real highlight of Node is building high-performance, scalable web applications-because it can handle large and high-throughput concurrent connections.

Basic System Installation

Node can run perfectly on Linux, Macintosh, and Solaris, and Ubuntu is a suitable Linux distribution. That's why we will try to install Node.js on Ubuntu 15.04, and the same steps can be used for installation on 14.04 as well.

  1. System Resources The basic system resources needed for Node.js depend on your architecture needs. In this tutorial, we will use a server with 1GB RAM, 1GHz processor, and 10GB disk space. We will perform a minimal installation, and there is no need to install a web server or database server.
  2. System Update Before installing Node.js, we need to update the system using the following command: apt-get update
  3. Installing Dependencies Node.js only requires some basic system and software functionality, such as ‘make,' ‘gcc,' and ‘wget.' If you haven't installed them yet, run the following command to install them: apt-get install python gcc make g++ wget

Downloading the Latest Version of Node JS v4.0.0

Visit the link to download the source code. Copy the link of the latest source code and download it using wget, as shown in the following command:

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

Once the download is complete, use the tar command to extract the files:

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

Installing Node JS v4.0.0

Now we can compile Node.js using the downloaded source code. Before compiling, switch to the directory where the source code is extracted on the Ubuntu server and run the configure script to configure the source code.

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

make install Node.js

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

The make command will take a few minutes to complete the compilation, so wait patiently.

Verify Node.js

Installation Once the compilation task is completed, we can verify if the installation is successful. Run the following command to confirm the version of Node.js:

root@ubuntu-15:~# node -v

v4.0.0-pre

Running Node in REPL mode without parameters on the command line will enter the Read-Eval-Print-Loop (REPL) mode. It has a simplified version of the Emacs line editor, through which you can interactively run JS and view the results.

Writing a Test Program

We can also write a simple terminal program to test if the installation is successful and working properly. To do this, we will create a “test.js” file containing the following code, as shown below:

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

var util = require(“util”);

console.log(“Hello! This is a Node Test Program”);

:wq!

Now to run the above program, execute the following command on the command line:

root@ubuntu-15:# node test.js

Running the above program in an environment where Node JS is successfully installed will result in the output shown in the above image. This program loads the class “util” into the variable “util,” and then uses the object “util” to run terminal tasks. The console.log command functions similarly to cout in C++.

Conclusion

That's it. If you are just starting to develop applications using Node.js, I hope this article has given you an overview of Node.js by installing and running it on Ubuntu. Finally, we can expect significant performance improvements from Node JS v4.0.0.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *