How to change the path where ruby gems are installed on OS 10.6.6 Ruby 1.8 and Rails 3

14,083

Solution 1

I would suggest using RVM (Ruby Version Manager) to control which version of Ruby you are installing your gems into. It will also help keep all the bundle and gem data in a folder in your home directory.

Solution 2

Although many Rubyists will recommend you RVM or RBENV, I do not use it. It's VERY slow and it pollutes your environment.

If you use Bundler, you dont need RVM at all - rubygem itself supports multiple versions of single gems. So you can just start using gems (e.g. gem install etc) and it will install into your $HOME/.gem directory by default. You can check the installation path using:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.9.3 (2013-02-06 patchlevel 385) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/lzap/.gem/ruby/1.9.3
  - RUBY EXECUTABLE: /usr/bin/ruby
  - EXECUTABLE DIRECTORY: /home/lzap/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/lzap/.gem/ruby/1.9.3
     - /usr/share/gems
     - /usr/local/share/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/

You can even change this with GEM_HOME environment variable. Happy gemming!

Share:
14,083
Kirill
Author by

Kirill

Making https://SmashNotes.com and teaching at https://SuddenSchools.org Occasionally interviewing rad humans on https://GeekAtSea.com Y Combinator alum. 1x investor. Living for today.

Updated on June 04, 2022

Comments

  • Kirill
    Kirill almost 2 years

    Whether I use gem install or bundle install for my gems, they don't work. Sometimes sudo gem install gets gems to work. I ran the gem list -d and which gem commands, and it seems that my system is configured such that all the gems get installed into " /Library/Ruby/Gems/1.8" but my environment expects them in "/usr/bin/gem". How could I properly correct this? I was under the impression that 'bundle' should be able to install a local, application specific copy of a gem?

  • PJP
    PJP about 13 years
    +1 for RVM. The OP needs to read the installation section, and make sure everything is completed - too many people only do it part way. And, once RVM is installed, never use sudo for installing any gems for a RVM-controlled Ruby or bad things will happen.
  • Kirill
    Kirill about 13 years
    If that is the only reasonable options, then according to RVM instructions I am supposed to find ".bash_profile" and add something to it. Where do I find the said file?
  • Pan Thomakos
    Pan Thomakos about 13 years
    It's located in your home directory (~/.bash_profile) if it doesn't exist, feel free to create it.
  • Kirill
    Kirill about 13 years
    Got'ya! I was searching for a file that didn't exist. thanks!
  • PJP
    PJP about 13 years
    You can use either ~/.bash_profile or ~/.bashrc, but you don't need to use both.
  • Kirill
    Kirill about 13 years
    I followed the instructions on the RVM website, but the results haven't changed. RVM is working, but 'which ruby' still points to /urs/bin/ruby. bummer
  • Pan Thomakos
    Pan Thomakos about 13 years
    Have you tried running the rvm 1.9.2 command for example? Does that change your ruby version?
  • Kirill
    Kirill about 13 years
    Somehow I was able to fix this and get RVM to run. I think I should have been more careful about following instructions :)
  • Max Cascone
    Max Cascone over 3 years
    how do we change these ruby env vars?