rails服务器无法启动; getaddrinfo:提供的nodename或servname,或者未知(SocketError)

时间:2015-02-27 15:45:53

标签: ruby-on-rails ruby osx-yosemite ruby-on-rails-4.2 ruby-2.2

我还没有找到问题的解决方案,但有几天前有人已经问过同样的问题 - (Rails Server Keeps Exiting (SocketError)

启动rails服务器后,系统会返回一些我无法理解的错误。要在我的Mac上安装Ruby on Rails,我执行了http://railsapps.github.io/installrubyonrails-mac.html

上列出的所有操作

这是我的终端回复:

$ rails server
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-28 02:14:46] INFO  WEBrick 1.3.1
[2015-02-28 02:14:46] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
Exiting
/Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:232:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:232:in `foreach'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:459:in `tcp_server_sockets'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/utils.rb:70:in `create_listeners'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:133:in `listen'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:114:in `initialize'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:45:in `initialize'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/rack-1.6.0/lib/rack/handler/webrick.rb:32:in `new'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/rack-1.6.0/lib/rack/handler/webrick.rb:32:in `run'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/rack-1.6.0/lib/rack/server.rb:286:in `start'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/server.rb:80:in `start'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/alexshel/workspace/myapp/bin/rails:8:in `require'
    from /Users/alexshel/workspace/myapp/bin/rails:8:in `<top (required)>'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client/rails.rb:27:in `load'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client/rails.rb:27:in `call'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client/command.rb:7:in `call'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client.rb:26:in `run'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/bin/spring:48:in `<top (required)>'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/binstub.rb:11:in `load'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Users/alexshel/workspace/myapp/bin/spring:13:in `require'
    from /Users/alexshel/workspace/myapp/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

请帮忙。

4 个答案:

答案 0 :(得分:13)

通过将127.0.0.1 localhost记录添加到private/etc/hosts文件来解决问题,该文件之前因某种原因被删除了。

答案 1 :(得分:1)

尝试更改为UNIX编码:

brew install dos2unix
sudo dos2unix -c mac /private/etc/hosts

答案 2 :(得分:0)

我在rails环境中遇到类似Redis的问题。我将端口号和“Redis”添加到我的mac上的/ private / etc / hosts文件中,它解决了错误。假设您的端口号为“1234”,您可以添加:1234 redis。对于localhost,您将添加:127.0.0.1 localhost。我希望这至少能为你的特定问题提供一些线索。

答案 3 :(得分:0)

对于遇到此问题的任何未来用户,我可以通过在private/etc/hosts文件的末尾添加以下内容来解决此问题。

127.0.0.1 YOURNAME-MacBook-Pro.local

YOURNAME-MacBook-Pro更新为您的计算机名称,并希望您将全部设置。