How to change the path where ruby gems are installed on OS 10.6.6 Ruby 1.8 and Rails 3
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!
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, 2022Comments
-
Kirill almost 2 years
Whether I use
gem install
orbundle install
for my gems, they don't work. Sometimessudo gem install
gets gems to work. I ran thegem list -d
andwhich 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 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 about 13 yearsIf 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 about 13 yearsIt's located in your home directory (~/.bash_profile) if it doesn't exist, feel free to create it.
-
Kirill about 13 yearsGot'ya! I was searching for a file that didn't exist. thanks!
-
PJP about 13 yearsYou can use either
~/.bash_profile
or~/.bashrc
, but you don't need to use both. -
Kirill about 13 yearsI 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 about 13 yearsHave you tried running the rvm 1.9.2 command for example? Does that change your ruby version?
-
Kirill about 13 yearsSomehow I was able to fix this and get RVM to run. I think I should have been more careful about following instructions :)
-
Max Cascone over 3 yearshow do we change these ruby env vars?