简体   繁体   中英

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. On my VPS I use Apache and Passenger, but when I start the application, I get errors like:

/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. But that is strange, cause it should not be using the preinstalled Ruby 1.8.7, but 1.9.3. On my CentOS 6.2 I installed RVM and Ruby 1.9.3, so I have this:

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. 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.

So the question is: How do I make Passenger load the needed Ruby version, not the preinstalled one?

This is tail of Apache error_log after restart:

[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. This option allows one to specify the Ruby interpreter to use. Source: Configuring Phusion Passenger

Try to start production server with

bundle exec [command]

It should take care of the dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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