10

https://www.railstutorial.org/book/beginning#sec-rails_server

I have reached this step, and I'm using the cloud9 environment. When I run the server as per Listing 1.7 on that tutorial, however, I get this error:

myname@rails-tutorial:~/workspace/hello_app $ rails server -p $PORT -b $IP
=> Booting WEBrick
=> Rails 4.2.0.beta2 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-10-30 21:44:22] INFO  WEBrick 1.3.1
[2014-10-30 21:44:22] INFO  ruby 2.1.1 (2014-02-24) [x86_64-linux]
Exiting /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `listen'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `each'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `foreach'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:459:in `tcp_server_sockets'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/utils.rb:75:in `create_listeners'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:132:in `listen'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:113:in `initialize'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:45:in `initialize'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `new'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `run'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/rack-1.6.0.beta/lib/rack/server.rb:288:in `start'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/ubuntu/workspace/hello_app/bin/rails:8:in `require'
    from /home/ubuntu/workspace/hello_app/bin/rails:8:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /home/ubuntu/workspace/hello_app/bin/spring:16:in `require'
    from /home/ubuntu/workspace/hello_app/bin/spring:16:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

I've tried specifying a different port, but that doesn't work and the cloud9 environment suggests to me I should just use the $PORT variable.

The error "Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)" implies that I already have a rails server running, but I don't. I'm not really sure what to do here and the tutorial doesn't suggest any method of troubleshooting this issue.

Josh Burson
  • 559
  • 4
  • 17

4 Answers4

16

I learned that you can use the command killall ruby to stop any of the ruby processes which helped me because I had mistakenly run the rails server -b $IP -p $PORT command at the ~/workspace level in the tutorial. I found the answer in can't open rails server

Community
  • 1
  • 1
Tommy
  • 161
  • 2
  • Tried running killall ruby, but it couldn't find any running processes. – Josh Burson Oct 31 '14 at 16:23
  • 2
    Just wanted to say I ran into this exact problem for the first time and was gratified that Googling the error message led to the solution—for my own darn tutorial! Signed, the author :-) – mhartl Jun 06 '16 at 18:49
9

I ended up starting the tutorial from scratch again and it worked fine, but anyone with this problem in the future may find this troubleshooting technique I received from cloud9's support team useful:


Try:

lsof -i:8080

This will give the app that occupies it.

If apache, stop it using:

sudo /etc/init.d/apache2 stop

Hope this answer is of use to anyone with this problem.

Josh Burson
  • 559
  • 4
  • 17
1

Probably you just had the other server still running. The one you initiate earlier on in he tutorial with the rails server command. You need to shut the other one down first using Ctrl+C, then try rails server -b $IP -p $PORT again

marfsco
  • 11
  • 1
-1
$ rails server -b $IP -p $PORT

Cloud9 uses the special environment variables $IP and $PORT to assign the IP address and port number dynamically. If you want to see the values of these variables, type echo $IP or echo $PORT at the command line.

It's likely that if you wait a few minutes (not more than 2), your OS will free up the port. If not, use a random port number over about 5,000 every time you run rails server, e.g.

$ rails server -b $IP -p 6789

Or, because your IDE is so sucky, you might consider using a different IDE.

7stud
  • 46,922
  • 14
  • 101
  • 127
  • "rails server -b $IP -p $PORT" is the command I used to get the error above. It's included in my question – Josh Burson Oct 31 '14 at 16:17
  • And using a number above 5000 doesn't help either. The server launches, but I can't access it in the browser via: https://rails-tutorial-c9-myname.c9.io , like I should be able to – Josh Burson Oct 31 '14 at 16:22
  • You seem to be biased against Cloud9, and your comments are completely unhelpful. – Josh Burson Oct 31 '14 at 17:17