Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Generate a Scaffold

Anthony Ho
Anthony Ho
10,228 Points

Can't start the rails server

Shows an error

[2014-10-13 12:46:24] INFO  WEBrick 1.3.1
[2014-10-13 12:46:24] INFO  ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0]
Exiting
/Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE)
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:206:in `listen'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:232:in `each'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:232:in `foreach'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:459:in `tcp_server_sockets'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/utils.rb:75:in `create_listeners'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:132:in `listen'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:113:in `initialize'
    from /Users/AnthonyHo/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:45:in `initialize'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `new'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `run'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/railties-4.0.1/lib/rails/commands/server.rb:84:in `start'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/railties-4.0.1/lib/rails/commands.rb:76:in `block in <top (required)>'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/railties-4.0.1/lib/rails/commands.rb:71:in `tap'
    from /Users/AnthonyHo/.rvm/gems/ruby-2.1.2/gems/railties-4.0.1/lib/rails/commands.rb:71:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

The error message Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE) is showing that you already have an instance of a web server running elsewhere, perhaps in another terminal tab.

Make sure you have stopped any other instances of rails server and try again.

Anthony Ho
Anthony Ho
10,228 Points

How do I stop other instances?

Sreng Hong
Sreng Hong
15,083 Points

i think it's control + c to close the rails server.

If you have access to the terminal window that the rails server is running then you can press control+C. If, however, you closed the window but the server is still running you will have to find the process and kill.

From the terminal you can run ps aux | grep rails which will list any running process that matches rails. You'll see an output such as

6443 ttys013    0:00.00 grep rails
5546 ttys014    0:04.52 ruby bin/rails server

In this example, the second entry is the server process. You can then pass the kill command the process ID to terminate the server. In our example the command would be kill 5546.

Anthony Ho
Anthony Ho
10,228 Points

I'm trying to start the rails server. I typed bin/rail server and it doesn't work I still have this problem

2 Answers

Daniel Cardenas
PLUS
Daniel Cardenas
Courses Plus Student 9,236 Points

Try this...

Type this in your terminal to find out the PID of the process that's using the 3000 port:

'lsof -wni tcp:3000'

Then, use the number in the PID column to kill the process:

'kill -9 PID'

Make sure you substitute PID with the actual number that you see under the PID for example 'kill -9 11734'

Hopefully that works.

Anthony Ho
Anthony Ho
10,228 Points

Sorry that didn't work

Anthony Ho
Anthony Ho
10,228 Points

It's okay I rebooted the terminal and it's fine now