[Rails] Port佔用問題 - Address already in use - bind(2) (Errno::EADDRINUSE)
錯誤訊息
開啟的時候發現port被佔用
$ rails s
=> Booting Puma
=> Rails 5.1.0.rc1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Exiting
/Users/XinYing/.rvm/gems/ruby-2.3.1/gems/puma-3.8.2/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
處理方式
先查佔用該port的PID
這邊舉例port3000
$ lsof -i tcp:3000
#OMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
#ruby 28143 ANXGANG 19u IPv4 0xaacecc8b906857cf 0t0 TCP *:hbci (LISTEN)
根據PID強制刪除
$ kill -9 28143
備註
雖然是月經文,但因為指令實在太難記,特別紀錄下:
- lsof: list open files
- -i: select IPv[46] files
參考
- http://stackoverflow.com/questions/31039998/address-already-in-use-bind2-errnoeaddrinuse
留言