简体   繁体   English

无法使用带有RVM的所需Ruby版本启动Rails应用程序?

[英]Can't start Rails application with the needed Ruby version with RVM?

I tried to deploy my first Rails 3.x app on my VPS which was not really successful. 我试图在我的VPS上部署我的第一个Rails 3.x应用程序,但这并不成功。 On my VPS I use Apache and Passenger, but when I start the application, I get errors like: 在我的VPS上,我使用Apache和Passenger,但是当我启动应用程序时,出现如下错误:

/var/www/my_domain_name/sample_app/config/initializers/wrap_parameters.rb:8: syntax error, unexpected ':', expecting kEND wrap_parameters format: [:json] ^

with a backtrace: 回溯:

0   /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb    245 in `load'
1   /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb    245 in `load'
2   /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb    236 in `load_dependency'
3   /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb    245 in `load'
4   /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/engine.rb    588 
5   /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/engine.rb    587 in `each'
6   /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/engine.rb    587 
7   /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 30  in `instance_exec'
8   /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 30  in `run'
9   /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 55  in `run_initializers'
10  /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 54  in `each'
11  /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 54  in `run_initializers'
12  /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/application.rb   136 in `initialize!'
13  /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/railtie/configurable.rb  30  in `send'
14  /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/railtie/configurable.rb  30  in `method_missing'
15  /var/www/slovnyky.com/sample_app/config/environment.rb  5   
16  config.ru   3   in `require'
17  config.ru   3   
18  /usr/lib64/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb    51  in `instance_eval'
19  /usr/lib64/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb    51  in `initialize'
20  config.ru   1   in `new'
21  config.ru   1

I figured out that the problem could be in the wrong Ruby version because 1.8.7 does not correctly recognize some hash syntax. 我发现问题可能出在错误的Ruby版本中,因为1.8.7无法正确识别某些哈希语法。 But that is strange, cause it should not be using the preinstalled Ruby 1.8.7, but 1.9.3. 但这很奇怪,因为它不应该使用预装的Ruby 1.8.7,而是1.9.3。 On my CentOS 6.2 I installed RVM and Ruby 1.9.3, so I have this: 在我的CentOS 6.2上,我安装了RVM和Ruby 1.9.3,因此我拥有以下功能:

ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
rvm list
rvm rubies
=* ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
#  * - default

so it's strange that I get: 所以我很奇怪:

sudo ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

Which is why I think that for some reason Passenger picks up the wrong Ruby version. 这就是为什么我认为出于某些原因,Passenger选择了错误的Ruby版本。 When I try to start the server like: 当我尝试像这样启动服务器时:

rails server

it works and I can access my application via MY_IP:3000 without any problems. 它可以正常工作,我可以毫无问题地通过MY_IP:3000访问我的应用程序。

So the question is: How do I make Passenger load the needed Ruby version, not the preinstalled one? 所以问题是:我如何让乘客加载所需的Ruby版本,而不是预装的版本?

This is tail of Apache error_log after restart: 重新启动后,这是Apache error_log的尾部:

[Thu Jul 26 20:29:10 2012] [notice] caught SIGTERM, shutting down
[Thu Jul 26 20:29:11 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jul 26 20:29:11 2012] [notice] Digest: generating secret for digest authentication ...
[Thu Jul 26 20:29:11 2012] [notice] Digest: done
[Thu Jul 26 20:29:11 2012] [notice] Apache/2.2.15 (Unix) DAV/2 Phusion_Passenger/3.0.12 PHP/5.3.3 configured -- resuming normal operations

Check " PassengerRuby " option in apache config. 检查Apache配置中的“ PassengerRuby ”选项。 This option allows one to specify the Ruby interpreter to use. 该选项允许指定要使用的Ruby解释器。 Source: Configuring Phusion Passenger 来源: 配置Phusion乘客

Try to start production server with 尝试使用以下方式启动生产服务器

bundle exec [command]

It should take care of the dependencies. 它应该照顾依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM