0
~ $ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
~ $ which ruby
/usr/local/bin/ruby
~ $ rails -v

    Rails 4 prefers to run on Ruby 2.0.

    You're running
      ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

    Please upgrade to Ruby 1.9.3 or newer to continue.

~ $ cat $(which rails) | head -1
#!/usr/bin/ruby
~ $ /usr/bin/ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
~ $ 

As you can see, Rails is not picking up the default version of Ruby which is 2.0.

Is it okay to modify the first line of Rails to #!/usr/local/bin/ruby?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Raj
  • 22,346
  • 14
  • 99
  • 142
  • @SabyasachiGhosh Yes I am using rvm – Raj Sep 16 '13 at 17:03
  • i guess you have multiple gem set and ruby version installed in your system. either set rvm default option or else use rvm use ruby_version. some time it will not pickup the default ruby version for your system – Sabyasachi Ghosh Sep 16 '13 at 17:05
  • Does this answer help ? http://stackoverflow.com/questions/18549107/which-ruby-version-am-i-really-running/18552313#18552313 – Anshul Goyal Sep 16 '13 at 17:14
  • Don't modify Rails. By doing so you'll create a maintenance problem for yourself. Rails updates often, and you'll have to manually change it each time you update your local copy. The better solution is to figure out WHY you system is acting the way it is and fix that. At that point, Rails will work the way it should, as will all the other Ruby gems. – the Tin Man Sep 17 '13 at 16:50

2 Answers2

2

In your project folder, add a .ruby-version file containing a string representing your preferred Ruby version. For example

2.0.0

This will ensure that RVM will switch to that version of Ruby as soon as you cd into that folder.

Almost all popular ruby version managers: rvm, chruby, rbenv honor .ruby-version file.

Alternatively, you can also specify your Ruby version by adding this line to the gemfile:

ruby '2.0.0'
Litmus
  • 10,558
  • 6
  • 29
  • 44
1

Is it okay to modify the first line of rails to #!/usr/local/bin/ruby?

No. Better way is using rbenv (https://github.com/sstephenson/rbenv) or rvm (https://rvm.io/).

Also you can remove /usr/bin/ruby and create symlink from /usr/local/bin/ruby (ln -s /usr/local/bin/ruby /usr/bin/ruby). But most likely you will get problems with gems.

Alexander Randa
  • 868
  • 4
  • 7
  • 2
    Removing `/usr/bin/ruby` and replacing it with a symlink is a bad solution; Most likely they're different versions, which would break all the ancillary apps that are bundled with Ruby and any gems that expect that particular version. This is a pathing issue that can be fixed by the proper use of rbenv or rvm. – the Tin Man Sep 16 '13 at 18:33
  • Then, if you understand that the advice isn't good, or appropriate, perhaps you should take out the suggestion to remove /usr/bin/ruby and replace it. The short "perhaps" warning makes it sound like there's an small chance of problems, but there is a great likelihood of it. – the Tin Man Sep 17 '13 at 16:07