9
votes

I want to use Rails with Ruby 2.1.0, but it's using Ruby 1.9.3 (the system's version).

I'm using rbenv to manage my Ruby versions. My steps were something along the lines of:

$ rbenv install 2.1.0
$ rbenv global 2.1.0
$ sudo gem install rails -v 4.0.2
$ rbenv rehash
$ rbenv versions
  system
* 2.1.0 (set by /home/dennis/.rbenv/version)
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
$ rails new app && cd app
$ rails server

Rails is using is Ruby 1.9.3 (x86_64-linux), according to localhost:3000/rails/info/properties. A log message from rails server gives: INFO ruby 1.9.3 (2012-04-20) [x86_64-linux].

I think Rails is using the system version of Ruby because the versions match.

$ rbenv local system
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rbenv local --unset  # Unset local Ruby version, go back to 2.1.0

Some things I've tried with no luck:

  • setting the local and shell versions of Ruby to 2.1.0 with rbenv
  • rehash rbenv shims (rbenv says to do this after installing executables)
  • made new Rails projects after switching to 2.1.0 just in case I made the projects while using 1.9.3
  • putting 2.1.0 in a .ruby-version file in the root of my project (suggested by @Agis)
  • restarting terminal session and starting a login bash shell (suggested by @Russel)
  • specifying the desired Ruby version in the project's Gemfile (suggested by @rlecaro2)

FWIW, I'm using Ubuntu 13.10 with the fish shell.

3
Check with which rails and which ruby that you're actually using the rbenv shimsBaldrick
which rails => /usr/local/bin/rails, which ruby => /home/dennis/.rbenv/shims/rubyDennis
Did You used RVM for installation?Abhinay
@Abhinay No, I don't even have RVM installed. I used rbenv with ruby-build to build & install Ruby 2.1.0.Dennis
@Dennis Mate, sorry to say but If you really want to Learn Rails with " no issues with installation ".Simply go with rvm otherwise these things will occur frequently. Even stackoverflow.com/users/497756/mpapis has suggested the same..Enjoy !!.If you say then I'll post all the steps below for you here.Abhinay

3 Answers

8
votes

Sounds silly, but did you restart terminal session?

Otherwise try and type

 /bin/bash --login
8
votes

You didn't tell how you installed rbenv, but I think it is per-user installation (which is default). In this case you should install gems without using sudo. When you did sudo gem install rails, it was installed in system ruby, not rbenv's selected one.

Solution - install rails without sudo:

rbenv global 2.1.0
gem install rails
rbenv rehash
4
votes

Try creating a .ruby-version file in the root of your project with the following contents:

2.1.0