Linux – Syntax error when starting Rails server, RVM could be the issue

linuxrubyruby-on-railsrvmUbuntu

I am getting the following error when trying to start my Rails application in production for the first time:

/var/www/railsapp/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end ...sion_store :cookie_store, key: '_intranet_session' ^

I have read that this could be an issue with the current ruby version, so I installed RVM and updated the running version.

**root@rails ~#** ruby -v
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2010.02
**root@rails ~#** rvm use 1.9.3
Using /usr/local/rvm/gems/ruby-1.9.3-p125
**root@rails ~#** ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]

I notice that the production version of Ruby is 1.9.3p125 but the development version is 1.9.3p0, not sure if that matters.

I then double checked the Rails version was the correct one:

**root@rails www/railsapp#** rails -v
Rails 3.1.4

I thought it would be worth restarting the server and then the application just for giggles but that didn't help either.

When reading a few other questions I noticed that if RVM isn't installed then running 'rvm list known' would fail, so I tested it:

**root@rails www/railsapp#** rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p358]
[ruby-]1.8.7-head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2-p180
[ruby-]1.9.2-p290
[ruby-]1.9.2[-p318]
[ruby-]1.9.2-head
[ruby-]1.9.3-preview1
[ruby-]1.9.3-rc1
[ruby-]1.9.3-p0
[ruby-]1.9.3[-p125]
[ruby-]1.9.3-head
ruby-head

# GoRuby
goruby

# TheCodeShop - MRI experimental patches
tcs

# JRuby
jruby-1.2.0
jruby-1.3.1
jruby-1.4.0
jruby-1.6.5
/usr/local/rvm/config/known

If it helps I am running the Turnkey Linux Rails appliance (TurnKey Linux 11.3 / Ubuntu 10.04 Lucid LTS).

I'm at a bit of a dead end of what to try, and advice would be greatly appreciated!

Best Answer

The problem is with the system environment.

What everyone failed to ask (including myself) was to see the full error logs. Doing so revealed he was using Passenger and it was loading the gem from 1.8.

More investigation shows RVM was loading as a system-wide install. So setting 1.9.3 as the system default and then re-install the passenger gem, then installing the apache2 module, then updating the apache configs fixed the issue.

This this box is dedicated for that one app, the above fix shouldn't be a problem. If you end up running more rails apps and need a more tightly defined environments, then read through this documentation http://beginrescueend.com/integration/passenger/. This will let you create a gemset for each app. I'm not sure how it will work with different ruby versions, as passenger will still have to be loaded from a single ruby install, but it might be able to run the scripts as a different ruby version?