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

时间:2012-07-23 19:25:01

标签: ruby-on-rails ruby passenger

我尝试在我的VPS上部署我的第一个Rails 3.x应用程序但这并不是很成功。在我的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] ^

带有回溯:

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

我发现问题可能出在错误的Ruby版本中,因为1.8.7无法正确识别某些哈希语法。但这很奇怪,因为它不应该使用预装的Ruby 1.8.7,而是1.9.3。在我的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

所以我很奇怪:

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

这就是为什么我认为由于某种原因Passenger选择了错误的Ruby版本。当我尝试启动服务器时:

rails server

它可以工作,我可以通过MY_IP:3000访问我的应用程序,没有任何问题。

所以问题是:如何让Passenger加载所需的Ruby版本,而不是预先安装的版本?

重启后这是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

2 个答案:

答案 0 :(得分:1)

在apache config中选中“ PassengerRuby ”选项。此选项允许指定要使用的Ruby解释器。资料来源:Configuring Phusion Passenger

答案 1 :(得分:0)

尝试使用

启动生产服务器
bundle exec [command]

它应该处理依赖关系。