SangSir丨艺术界的一朵奇葩丨至一网络科技 - nodejs
type: channel
link: https://www.sangsir.com/tag/nodejs/
items: 解决运行Nodejs代码Error: listen EADDRINUSE
items: Centos系统环境下安装Node.Js

解决运行Nodejs代码Error: listen EADDRINUSE
type: item
date: 2015-06-06T14:20:00+08:00
description: root@xxx:~/hexo# hexo server [error] Error: listen EADDRINUSE Error: listen EADDRINUSE at errnoException (net.js:901:11) at Server._listen2 (net.js:1039:14) at listen (net.js:1061:10) at Server.listen (net.js:1135:5) at Function.app.listen (/root/.nvm/v0.10.25/lib/node_modules/hexo/node_modules/express/lib/application.js:533:24) at /root/.nvm/v0.10.25/lib/node_modules/hexo/lib/plugins/console/server.js:86:9 at /root/.nvm/v0.10.25/lib/node_modules/hexo/lib/post/load.js:67:7 at /root/.nvm/v0.10.25/lib/node_modules/hexo/node_modules/async/lib/async.js:116:25 at /root/.nvm/v0.10.25/lib/node_modules/hexo/node_modules/async/lib/async.js:24:16 at exports.post (/root/.nvm/v0.10.25/lib/node_modules/hexo/lib/plugins/generator/asset.js:50:3)原因是Nodejs所监听的端口被占用，查找端口占用的程序并kill掉即可root@xxxxx:~/hexo# fuser -n tcp 80 80/tcp: 705 715 716 717 718 root@xxxxx:~/hexo# kill 705有用的就是里面的 fuser -n tcp 80 和 kill 了，就是酱紫！

Centos系统环境下安装Node.Js
type: item
date: 2015-06-06T09:40:00+08:00
description: 首先说明Node.Js的环境要求并查看是否适合Node.Js安装：GCC 4.2 or newer G++ 4.2 or newer Python 2.6 or 2.7 GNU Make 3.81 or newer libexecinfo(FreeBSD and OpenBSD only)查看发行版本：cat /etc/redhat -release查看GCC：rpm -q gcc rpm -q gcc-c++安装GCC等：yum -y install gcc gcc-c++ kernel-devel查看python版本：python -V用包工具安装基本可以解决后面的安装失败：yum -y update && yum -y groupinstall "Development Tools"下载Node.Js：首先去官网找到适合自己的32位或64位的包，https://nodejs.org/download我这里用的是64位：http://nodejs.org/dist/v0.12.4/node-v0.12.4-sunos-x64.tar.gz安装Node.Js：cd /usr/src wget http://nodejs.org/dist/v0.12.4/node-v0.12.4-sunos-x64.tar.gz tar -xf node-v0.12.4-sunos-x64.tar.gz cd node-v0.12.4-sunos-x64 ./configure make make install检查是否安装成功：node -v npm -v