|
Recently, I have been interested in learning Node.js. This is a server-side Java programming platform, which allows developers to write Java code in the server, and there are many CentOS users are trying to learn the language of the development environment. This is what I want to do this tutorial purposes.
First make sure you have a CentOS 7. Because it is the only thing I use version, of course, there is no absolute guarantee that this guide can also be used in other editions.
From source to install Node.js
First we install from source Node.js. I really like to install the software from source code. Open a new terminal tab and run the following command to download the installation file you want to use on your CentOS 7 machines.
wget http://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz
As you can see from the above command, 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, you need to install some packages on CentOS machine, so we can compile. So you open the terminal, enter the following.
sudo yum install gcc gcc-c ++
Wait for the installation and operation of these packages, use the following commands to configure and compile.
./configure
make
Above it will take some time to complete, do not worry because the compiler will take some time. Then use the following command to install on your system Node.js.
sudo make install
After installation is complete, you can start using the Node.js. And to ensure the correct version installed, you can use the following command to check.
node --version
When you run the above command, I get the following message.
v0.12.0
How to Install Node.js library from EPEL
Another effective and easy way to install Node.js is from the official repository. This also ensures that you can access to the EPEL repository, you can run the following command.
sudo yum install epel-release
You can now use the yum command to install Node.js.
sudo yum install nodejs
Because I need to manage the development process node packet, I would also like to install a new public management package manager, use the following command.
sudo yum install npm
Write our first Node.js program.
Write Hello World application in Node.js is very easy! Simpler than Python. You need to do is write the following code in a file and save it as something.js.
console.log ( "Hello World");
Us just created saved as hello.js. Then in order to run it, we need to use the following command.
node hello.js
Now open your text editor and add the following code hello.js. You can copy and paste, but I strongly recommend that you enter these yourself because this is a good opportunity to familiarize yourself with the Node.js.
var http = require ( 'http');
http.createServer. (function (request, response) {response.writeHead (200, { '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 for beginners, a bit complicated, but it is not difficult to understand. Access your browser to http: / / www.localhost: 8000 /, the above code, it will display "Hello World."
If you want to know more about Node.js content, please visit nodejs.org.
in conclusion
If you find the right guidance and follow the instructions to do it very carefully, I believe that Node.js is not difficult to install on CentOS operating system. I hope this tutorial will help you install it. |
|
|
|