2

I am using rbenv on Debian. Debian came pre-installed with ruby 1.9.3. I installed rbenv and used it to install ruby 2.1.2. I then used rails new to make a fresh rails application.

rbenv versions

gives

system
* 2.1.2 (set by /home/jordanmorris/code/TestRail/.ruby-version)

rbenv global gives 2.1.2
rbenv local (in the new application folder) gives 2.1.2
ruby -v gives 2.1.2
which ruby gives /home/jordanmorris/.rbenv/shims/ruby

However, when I use rails server (node.js), view the 'Welcome aboard site' and click "About your application’s environment", it reports:
Ruby version 1.9.3-p484 (x86_64-linux)

Why is this not displaying the version set with rbenv as expected, and is this a cause for concern?

I only have one version of rails installed, afaik, and it reports correctly (4.1.4).

Jordan Morris
  • 2,101
  • 2
  • 24
  • 41
  • 2
    in your application folder if you type `which ruby` do you get the rbenv ruby or the system ruby? – Anthony Feb 04 '15 at 13:29
  • @Anthony `which ruby` gives `/home/jordanmorris/.rbenv/shims/ruby` – Jordan Morris Feb 05 '15 at 20:07
  • For testing, can you add the line `ruby '2.1.2'` to your Gemfile, run `rails server`, and check the application's environment again? – Mike Sherrill 'Cat Recall' Feb 06 '15 at 00:01
  • Is `~/.rbenv/shims` the [first directory in your path](https://github.com/sstephenson/rbenv#understanding-path)? – Mike Sherrill 'Cat Recall' Feb 06 '15 at 00:04
  • @MikeSherrill'CatRecall' The shims path is at the start of my $PATH. Interesting - when I add `ruby'2.1.2'` to my Gemfile, `rails server` fails with `Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2` – Jordan Morris Feb 06 '15 at 03:08
  • I created another fresh application with `rails new`, and I found this file in a file called `rails` in `[application_folder]/bin/`. It contains the following: `#!/usr/bin/env ruby1.9.1` `begin` `load File.expand_path("../spring", __FILE__)` `rescue LoadError` `end` `APP_PATH = File.expand_path('../../config/application', __FILE__)` `require_relative '../config/boot'` `require 'rails/commands'` – Jordan Morris Feb 06 '15 at 03:13
  • Check all the sources at ["Choosing the Ruby version"](https://github.com/sstephenson/rbenv#choosing-the-ruby-version). What do you have? – Mike Sherrill 'Cat Recall' Feb 06 '15 at 03:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/70367/discussion-between-jordan-morris-and-mike-sherrill-cat-recall). – Jordan Morris Feb 06 '15 at 07:30

1 Answers1

0

This answer helped me.

The problem was that I installed rails using sudo.

rbenv operates on a per-user basis. So, rbenv install installed ruby 2.1.2 for jordanmorris, whereas sudo gem install rails installed rails using the only version of ruby/gem installed for root (1.9.3).

Afterwards, every time I ran rbenv or ruby, they used the expected rails version determined by rbenv, but every time I ran rails new or rails server, it would use the rails installed on top of ruby 1.9.3, that being the only instance of rails existing.

I followed these steps to fix it:

  1. Uninstall rails and it's dependencies (just because I like to keep a tidy house).
  2. Install rails and it's dependencies WITHOUT using sudo.
  3. Run rbenv rehash.
  4. Regenerate a new application (rails new).

The correct version now displays in the Welcome aboard -> About your application’s environment page.

Also note, the rails new command will create an application which uses spring. Consider installing rbenv-binstubs to avoid stub clashes with rbenv.

Community
  • 1
  • 1
Jordan Morris
  • 2,101
  • 2
  • 24
  • 41