How to deploy nodejs to linux and run out of hello world?

10-30-2023

Install VMware first.

1. Download VMware

Because we don't need to program on linux (unless you are a big cow || pretending to be a master), we chose to install linux on the virtual machine. At present, the mainstream virtual machine platforms are VMware and virtualbox, the former is paid, and the latter is a free version. You can install it at will. We use VMware here.

2. Install VMware

Double-click the downloaded installation package file to start the installation. ...

A. For me with obsessive-compulsive disorder, this interface goes directly to the next step, and there is nothing wrong with Lao Tie-

B.here, if you don't agree, then it's gone, then, v _ v.

C. Here's the key point. For some neat programmers who don't want to install the application software on their own C drive, they need to click the change button on this interface.

D. I don't know if you have any magical operation. As a lazy person, I just replaced C with D directly.

E. then there is the next crazy step-> finally click install, and the computer will start working.

F. After the installation is completed, the following interface pops up, where we click the license button (it is highly recommended that you buy genuine products).

G. After entering the license page input interface, I unconsciously thought of Du Niang. Here, I strongly recommend that you use genuine software again.

H click finish on the final finish page, and the VMware installation is completed.

Secondly, install linux.

Step 1 download linux

I won't repeat the myth about the birth of linux here. Let's just take a screenshot and play it last step.

Download address: http://www.jb51.net/softs/188482.html

Step 2 install linux

A. double-click the VMware button on the desktop to open it, and click the huge "new virtual machine" button.

B. Select typical, and click Next. If the system doesn't match the linux installation package you downloaded on this page, you need to manually select it.

C. Here you need to give your virtual machine a name.

D. as usual C->D

E. These things are not very good. Go directly to the next step and complete the virtual machine configuration.

F. The advantage of VMware is that so far, we don't have to do anything. You can tease your sister and play LOL. Because VMware has helped us with the rest of the work.

G. After the installation, we entered the desired linux interface, which was not as bad as we thought-

H. Linking linux with xshell

A) it's really not difficult to install xshell, so I won't talk about it here. First, we get the ip of the virtual machine.

Click the linux button-> enter the password that we set to install the virtual machine in the password box-> after completing the basic settings-> to enter.

Liunx Desktop-> Right-click -> open in terminal to open the liunx console, enter ifconfig command and press Enter.

B) open xshell and use alt+n shortcut key.

Enter the ip obtained in the previous step in the host name.

C) the content of ifconfig output in xshell is the same as that in virtual machine, and xshell links successfully.

1. Enter the installation directory.

cd /usr/local/

2. Upload the nodejs installation package

Rz-> select the downloaded node installation package file.

3. Unzip the nodejs installation package

xz -d node-v8.1.2-linux-x64.tar.xz tar -xvf node-v8.1.2-linux-x64.tar

4. Rename

mv node-v8.1.2-linux-x64 node

5. Add environment variables

Vim /etc/profile-> and add three lines at the end of the file (for vim operation, please do it yourself): exportnode _ home =/usr/local/nodeexportpath = $ path: $ node _ home/binexportnode _ path = $ node _ home/lib/ After the configuration of node_modules is completed, execute the source /etc/profile. Is it ok to enter node -v in the command line?-In order to ensure that the configuration can be used under each account, vim /root/.bashrc is needed, and the source etc/profile is added at the end of this file, and everything will be fine. .....

6. Create a hello world program

mkdir -p /usr/local/demo/vim /usr/local/demo/helloworld.js

Enter the following in the helloworld.js file.

var http = require('http'); http.createServer(function(req, res) {res.end('hello world...')}).listen(8080); Console.log ('service started, listening on port 8080 ...')

At this point, we can access the service locally through the virtual machine.

Access node service through virtual machine.

But it is not accessible in the physical host.

Why is this? ? ? Turn off the firewall

Baidu found for a long time that the firewall should be turned on for the virtual machine, so the physical host can't access it. Just execute the following two instructions.

Systemctl stop firewall d.service # stop firewall systemctl disable firewall d.service # prohibit firewall from starting.

Open a browser and visit http://192.168.79.128:8080/

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us