如何在Ubuntu中释放端口

时间:2014-03-19 04:57:16

标签: ruby-on-rails port

我想使用port no localhost:3000 for rails并且已经采取了其他进程如何免费使用此端口?

我已经运行了这个命令

ruby abc/script/server

并面临此错误

/usr/lib/ruby/1.9.1/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /usr/lib/ruby/1.9.1/webrick/utils.rb:85:in `new'
from /usr/lib/ruby/1.9.1/webrick/utils.rb:85:in `block in create_listeners'
from /usr/lib/ruby/1.9.1/webrick/utils.rb:82:in `each'
from /usr/lib/ruby/1.9.1/webrick/utils.rb:82:in `create_listeners'
from /usr/lib/ruby/1.9.1/webrick/server.rb:82:in `listen'
from /usr/lib/ruby/1.9.1/webrick/server.rb:70:in `initialize'
from /usr/lib/ruby/1.9.1/webrick/httpserver.rb:45:in `initialize'
from /usr/lib/ruby/vendor_ruby/rack/handler/webrick.rb:10:in `new'
from /usr/lib/ruby/vendor_ruby/rack/handler/webrick.rb:10:in `run'
from /var/www/abc/vendor/rails/railties/lib/commands/server.rb:111:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from abc/script/server:3:in `<main>'

4 个答案:

答案 0 :(得分:3)

netstat -tulpn | grep 3000 - 将为您提供流程的PID

例如:

tcp    0   0 0.0.0.0:3000    0.0.0.0:*  LISTEN      5726/ruby1.9.1 

此处5726是PID,使用kill -9 5726

将其删除

答案 1 :(得分:2)

答案 2 :(得分:1)

尝试这样的事情:

lsof -wni tcp:3000

将显示如下:

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ruby    3824 rony    9r  IPv4  50665      0t0  TCP *:3001 (LISTEN)

然后使用此PID

终止此操作
kill -9 3824

谢谢!

答案 3 :(得分:0)

您也可以在其他端口上启动rails服务器

rails server -p 4000