What is the default search path for Ruby gems? i.e. the default GEM_HOME

20,591

Type gem env. That will tell you what you want to know.

Share:
20,591

Related videos on Youtube

Max Jacobson
Author by

Max Jacobson

Aw, shucks.

Updated on July 09, 2022

Comments

  • Max Jacobson
    Max Jacobson almost 2 years

    What is the default search path for Ruby gems? I'm trying to figure what directories I can pass to gem's --install-dir switch, so that I don't have to set the environment variable GEM_HOME for the gems to be found.

    In particular, if I install the gem jekyll via

    $ gem install --bindir /usr/local/bin --install-dir /usr/local/lib/ruby/gems/1.8 jekyll
    

    then /usr/local/bin/jekyll can't find its libraries without explicitly setting GEM_HOME:

    $ jekyll --help
    /usr/lib/ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem jekyll (>= 0) (Gem::LoadError)
        from /usr/lib/ruby/1.8/rubygems.rb:214:in `activate'
        from /usr/lib/ruby/1.8/rubygems.rb:1082:in `gem'
        from /usr/local/bin/jekyll:18
    $ GEM_HOME=/usr/local/lib/ruby/gems/1.8 jekyll --help
    Jekyll is a blog-aware, static site generator.
    [ ... ]
    

    It seems that ruby itself will look in the directories listed in the Ruby variable $LOAD_PATH, which can be augmented by the environment variable RUBYLIB. However, where does the rubygem system search for gems?

  • barlop
    barlop over 4 years
    it gives three directories eg on osx /Library/Ruby/Gems/2.3.0 . and /Users/apple/.gem/ruby/2.3.0 and /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/l‌​ib/ruby/gems/2.3.0 . So which is default for GEM_PATH and which is default for GEM_HOME?
  • David Hull
    David Hull about 3 years
    You can use gem env gemhome and gem env gempath. To find the user gemhome, you can use ruby -e 'print Gem.user_dir'