VMware安装node环境
1,下载对应linux版本的node
2,xshell,命令lrzsz上传到指定位置或者xftp拖过去;
3,tar -xvf 文件名解压,最好重命名 mv 文件名 new name;
4,配置环境变量:
一定要执行这句话:(否则不成功)
source /etc/profile
注意:如果环境配置了还不行的方法:
在线升级centos编译器-》编译一下—》再配置
sudo yum install gcc gcc-c++
./configure
make&&sudo make install
继续步骤4
项目运行:
可随便新建个js文件:
hello,js
var http = require('http');
http.createServer(function(req, res){
res.writeHead(200,{'Content-Type': 'text/plain'});
res.end('hello world');
}).listen(3000);
console.log("http server is listening at port 3000.");
通过主机访问:
注意:
有些是虚拟机和内网网都能ping通,但是访问不了,可尝试关掉虚拟机linux的防火墙(CentOS7):
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
真实项目放上去也可以,我的项目是node服务,需要pm2起服务:
pm2命令需要自行安装(pm2命令百度):
npm install pm2 -g