How To Install Node.js on CentOS 7

Lately, I've been more interested in learning Node.js. This is a server-side programming for the Java platform that allows developers to write Java code on the server, and there are many CentOS users who are struggling to learn the language's development environment. That's exactly what I wanted to do with this tutorial.

First make sure you have CentOS 7. Since it's the only version I'm using, there is of course no guarantee that this guide will work on other versions as well.

Installing Node.js from Source

First we need to install Node.js from source. I really like installing software from source. Open a new terminal tab on your CentOS 7 machine and run the following command to download the required installation files.

wget https://nodejs.org/dist/v6.11.3/node-v6.11.3.tar.gz

You can see from the above command how we can use wget to operate.

Then extract the tar file as shown below.

tar xvf node-v6.11.3.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 your open terminal, type the following.

sudo yum install gcc gcc-c++

Wait for these packages to be installed and run, configure and compile with the following commands.

./configure
make

above will take some time to complete, don't worry as it will take a while to compile. Then use the following command to install Node.js on your system.

sudo make install

Once installed, you can start using Node.js. And to make sure the correct version is installed, you can check with the following command.

node --version

Beijing java job search group 145471323


Install express framework

$ npm install -g express

$ npm install -g express-generator

create express demo

$ express -e nodejs-demo
$ cd nodejs-demo && npm install

run
DEBUG=nodejs- demo:* ./bin/www


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326509552&siteId=291194637