[LRUG] Rails/RVM path confusion

Murray Steele murray.steele at gmail.com
Sun Sep 22 06:46:30 PDT 2013


It's been a while since I used rvm, so it may have changed, but here's what
I think is happening.

1. You install rvm and through it ruby 2.0.0-p247.
2. You install rails 4.0.0 and this goes into the "ruby-2.0.0-p247" gem
set.
3. You create a new rails app using called r1
4. You set a .rvmrc in this rails app to use a gem set called "r1".  This
is really the "ruby-2.0.0-p247 at r1" gem set.
5. When you change into the r1 directory rvm picks up the .rvmrc and
switches you from the "ruby-2.0.0-p247" gem set (the default for your ruby
2.0.0-p247 install) to the "r1" gem set (full name "ruby-2.0.0-p47 at r1").

The rails gem you installed in step 2. is not available in the r1 gem set
(because the "ruby-2.0.0-p247" gem set and "ruby-2.0.0-p247 at r1" gem sets
don't share anything), so that's why typing rails in r1 directory is not
using the rails 4 gem you installed earlier.

What makes it weird is that there is a gem set that is shared; each ruby
install that rvm manages has a "@global" gem set (it usually contains rake
and rdoc, maybe rubygems itself) (see: http://rvm.io/gemsets/global).  This
gem set is different to the un-named gem set that you get when you just
"rvm use ruby-2.0.0-p247".  If you want to  install gems to it specifically
(for example, another gem that's useful to have in @global is bundler), you
have to explicitly ask rvm to use it with "rvm use ruby-2.0.0-p247 at global".

Of course, that's not just about gems that are installed. It's also about
what binaries are available, so rvm manages your PATH variable to make sure
that /bin from the @global gem set is available and also /bin from the
current gem set is available too.

I mean, rvm does loads of other shell manipulation stuff.  It is useful to
have separate paths and environments for each rails app as it isolates it
and it's dependencies and thus makes it closer to the eventual production
deployment environment.  Of course, without wanting to invite a holy war,
it's worth noting that rvm and gem sets are not the only solution.  For
example, without ditching rvm, you can ignore gem sets and just use bundler
to install all the ruby dependencies locally to the application.  You might
want to look at this article for some ideas:
http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/

Hope some of that helps.

Cheers

Murray

On 21 September 2013 22:35, gvim <gvimrc at gmail.com> wrote:

> I install Ruby 2.0.0 and Rails 4.0.0 via RVM on OS X 10.8 in my standard
> user account. Fine. I check my `ruby` and `rails` are both coming from the
> right place. Good so far:
>
> /Users/<me>/.rvm/rubies/ruby-**2.0.0-p247/bin/ruby
> /Users/<me>/.rvm/rubies/ruby-**2.0.0-p247/bin/rails
>
> Next, I create my first Rails app with `rails new r1` and inside the new
> r1 app directory I setup my .rvmrc with `rvm --rvmrc --create 2.0.0 at r1`
> but `which rails` now returns  /usr/local/rails so I check my $PATH and
> discover that:
>
> /Users/<me>/.rvm/rubies/ruby-**2.0.0-p247/bin
>
> ... had now become
>
> /Users/<me>/.rvm/rubies/ruby-**2.0.0-p247 at global/bin
>
> ... which explains why my newly installed rails binary can't be found
>
> So, 2 questions:
>
> 1. Why has my rails path become screwed? Must I REALLY have a new PATH
> entry for every Rails app I create?
> 2. What magic is Ruby/Rails/RVM using to alter my PATH because ~/.bashrc
> doesn't contain everything in $PATH and ~/.bash_profile only contains:
>
> [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
>
> gvim
> ______________________________**_________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/**listinfo.cgi/chat-lrug.org<http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130922/1ec6f017/attachment.html>


More information about the Chat mailing list