19

I manually built Ruby 1.9.2 on Snow Leopard. Now I can’t find my old GEM files. I’m guessing they're in a different path now or something. So I have three questions:

  • What is the "old" gem path, where gem install sinatra puts the sinatra gem?
  • What is the "new" gem path, which is set when I build Ruby manually?
  • How do I change it so Ruby finds my gems again?
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
MrB
  • 199
  • 1
  • 1
  • 5

3 Answers3

46

Typing gem env (Using your old Ruby install's gem command) at a command prompt gives something similar to:

> RubyGems Environment:
>   - RUBYGEMS VERSION: 1.3.6
>   - RUBY VERSION: 1.9.1 (2009-07-16 patchlevel 243) [i386-mingw32]
>   - INSTALLATION DIRECTORY: C:/Ruby19/lib/ruby/gems/1.9.1
>   - RUBY EXECUTABLE: C:/Ruby19/bin/ruby.exe
>   - EXECUTABLE DIRECTORY: C:/Ruby19/bin
>   - RUBYGEMS PLATFORMS:
>     - ruby
>     - x86-mingw32
>   - GEM PATHS:
>      - C:/Ruby19/lib/ruby/gems/1.9.1
>      - C:/Users/Username/.gem/ruby/1.9.1
>   - GEM CONFIGURATION:
>      - :update_sources => true
>      - :verbose => true
>      - :benchmark => false
>      - :backtrace => false
>      - :bulk_threshold => 1000
>   - REMOTE SOURCES:
>      - http://rubygems.org/

(On Windows... I imagine Snow Leopard will have a similar format)

The GEM PATHS field is the interesting thing here. If you go to those directories listed, you should see a folder named cache. That will contain a list of .gem files corresponding to all the installed gems in that specific directory. You should just be able to call gem install *gemname* on each of those gem files (using your new Ruby install's gem command).

EDIT: Mistakenly referred to INSTALLATION DIRECTORY instead of GEM PATHS. Greg reminded me that there are multiple locations known by a specific installation of Rubygems. All of those locations needs to be checked for gems used by that installation of Ruby.

jason.rickman
  • 13,931
  • 1
  • 22
  • 14
  • I'm not sure of Rubygem's behavior for dependencies when installing from a local .gem file. You might want to include the --ignore-dependencies flag to avoid pulling dependencies from a remote source (since presumably you already have all necessary dependencies locally). – jason.rickman Nov 20 '10 at 14:12
  • 1
    Windows Gem configuration is not the same as Snow Leopard, because Apple configures the default locations, and want their own gems, plus the user gems, plus user `sudo` gems. Microsoft doesn't include Ruby so it's the Ruby installer for Windows that determines the locations. – the Tin Man Nov 20 '10 at 16:51
  • @Greg : Regardless of who determines the install locations, doesn't Rubygems know where that location is? Apologies if I'm outside my realm of knowledge here; I assumed Rubygems would work the same on all supported OSs. – jason.rickman Nov 20 '10 at 18:31
  • 1
    From my experience, having multiple versions of Ruby installed, one in `/usr/bin/ruby`, and one in `/usr/local/bin/ruby` results in separate installations of the gems. It might be that they're kept in the same place, but gem couldn't find them. I haven't bothered to find out why. With RVM it's a non-issue. – the Tin Man Nov 20 '10 at 23:59
  • If you install another version of Ruby you'll see that gems installed using it will be in another path, based on that Ruby's version. The native drivers installed by some gems probably preclude the ability to combine all installed gems into one folder. – the Tin Man Nov 21 '10 at 00:02
11

Your "old" gems would be relative to the Ruby that came bundled with the Mac because the gem command is included with Ruby 1.8.7, which is stock on Snow Leopard. If your which ruby shows /usr/bin/ruby, your gem environments should be similar to:

- GEM PATHS:
   - /Library/Ruby/Gems/1.8
   - /Users/greg/.gem/ruby/1.8
   - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

If you are using RVM you might be able to tell it to copy your gems from the system gemset to one under RVM's control. I haven't tried doing that as I install RVM immediately and let it handle all my Ruby installation and then I ignore the system's installation.

If your which ruby shows /usr/local/bin/ruby then the gem env command should reflect the changed path for the version you compiled from source.

I'm curious WHY you would build it manually, when RVM is available to handle all the configuration and installation, and largely remove any concerns about where things are and whether you've just stomped on the system's installed version.

When RVM has installed a Ruby version, it will all be in ~/.rvm and your Gems will be nicely located there too. You'll be able to manage the gems as gemsets, relative to each version of Ruby, and switch back and forth instantly. Or, even better, you can run a command/program in each version of Ruby you have installed to test them using rvm ruby 'some command'.

Notice in the above gem env output that gems are in three separate areas on the disk. Under RVM's control they're in RVM's sandbox:

- GEM PATHS:
   - /Users/greg/.rvm/gems/ruby-1.9.2-p0
   - /Users/greg/.rvm/gems/ruby-1.9.2-p0@global

That makes it trivial for me to back them up, or blow them away if I want to.

I used to compile my rubies from source on my Macs and Linux boxes. I use RVM for that now. It's so much better than doing it by hand.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
4

I believe the standard gem install path on OS X is:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256