RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems, and a server for distributing them. It is analogous to EasyInstall for the Python programming language. RubyGems is now part of the standard library from Ruby version 1.9.
That said, what's the difference between GEM_HOME and GEM_PATH?
GEM_PATH provides the locations (there may be several) where gems can be found.
GEM_HOME is where gems will be installed (by default).
(Therefore GEM_PATH should include GEM_HOME).
Also interesting notice. At least on Wndows XP, don't know about other platforms.
Set GEM_HOME in Windows:
C:\>set GEM_HOME=C:\sbox\ruby\dump\.gems
Now let's check this.
1) In Windows ENVs. All OK, as expected:
C:\>set
...
GEM_HOME=C:\sbox\ruby\dump\.gems
...
2) With gem env. Notice it puts GEM_HOME along with GEM_PATHs but at the first place:
C:\>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/sbox/ruby/dump/.gems
- RUBY EXECUTABLE: C:/Ruby200/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/sbox/ruby/dump/.gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/sbox/ruby/dump/.gems
- C:/Documents and Settings/User/.gem/ruby/2.0.0
- C:/Ruby200/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
3) Now with bundle env:
C:\>bundle env
Bundler 1.3.4
Ruby 2.0.0 (2013-02-24 patchlevel 0) [i386-mingw32]
Rubygems 2.0.3
GEM_HOME C:\sbox\ruby\dump\.gems
GEM_PATH
GEM_PATH is empty, it means default value. But from where does it take the default value? See gem env.
Related
I recently installed Ruby 2.0.0 on OS X 10.8.3 by compiling from source code. I checked the version with
$ ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
And I checked my gem version with
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-12
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ehartsuyker/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :benchmark => false
- :sources => ["http://rubygems.org/", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://rubygems.org/
- http://gemcutter.org
I noticed that the reported version of Ruby here does not match the version I installed. I don't know if this matters or not.
I have a simple piece of code called encrypy.rb that I'm running. After installing the 'rsa' gem with gem install rsa.
require 'rubygems'
require 'rsa'
key = RSA::KeyPair.generate(128)
ciphertext = key.encrypt("message")
puts(ciphertext)
When I run it, it gives an error saying it can't find the gem.
$ ruby encrypt.rb -Idirectory '/Library/Ruby/Gems/1.8'
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- rsa (LoadError)
from /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from encrypt.rb:2:in `<main>'
So the question is, why isn't Ruby finding the gem despite seeming to know where it is? And how can I fix it?
Ruby 1.8.7 is shipped with OS X. It seems that gem is seeing that version instead of your manually installed 2.0.0. As others already suggested, using RVM or rbenv (which one depends on personal preference) makes handling different ruby environments much easier. You can find those tools and descriptions for them in the following places:
RVM: https://rvm.io/
rbenv: https://github.com/sstephenson/rbenv
I just migrated to a new Mac with OS X Lion. For some reson I can't install new Ruby gems anymore. Or rather: I can install them, but not find them.
This is my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-11
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/Jens/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Running the gem crack in irb works fine:
>> require 'rubygems'
=> false
>> require 'crack'
=> true
But when I try to do the same in my text editor (Textwrangler) I run into this:
custom_require.rb:31: in `gem_original_require': no such file to load -- crack (LoadError)
Any suggestions?
Maybe a pointer in the right direction: I've had problems on Lion with different ruby versions being installed. Problem was that some programs calling ruby (in my case git for a pre-commit hook) had their $PATH variable different; as a result another version of ruby was found first (and that version didn't have the gems installed).
So to debug, try printing out the version of both rubys (rubies?), and the PATH variable (something like print RUBY_VERSION and print ENV["PATH"]; maybe also print ENV["GEM_HOME"]. See if that leads to anything.
FYI: for me the solution in the end was to upgrade from git 1.7.3 to 1.7.7; it wasn't clear to my why things didn't work in 1.7.3 (why the PATH was different), but who cares; it works again :))
I had Ruby 1.9.2 install, but I uninstalled it long ago. Today I installed a brand new version of Ruby 1.9.3, downloaded gem and set it up with ruby setup.rb.
I then noticed that installing gems failed, so I checked gem environment and this is what I get:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [i386-mingw32]
- INSTALLATION DIRECTORY: c:/Ruby192/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: C:/Ruby193/bin/ruby.exe
- EXECUTABLE DIRECTORY: c:/Ruby192/lib/ruby/gems/1.9.1/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- c:/Ruby192/lib/ruby/gems/1.9.1
- C:/.gem/ruby/1.9.1
- C:/Ruby193/lib/ruby/gems/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
It seems messing up the new installation (Ruby193) with the old one (Ruby192).
ruby -v yields, correctly, ruby 1.9.3p0 (2011-10-30) [i386-mingw32].
How to solve the problem?
EDIT: I had GEM_HOME and RUBYLIB environment variables set up to the old directories. Updating them solved the problem.
You shouldn't need to download gem or run ruby setup.rb.
I recommend removing all references to old rubies from your path environment variable and then downloading 1.9.3 from rubyinstaller.org install it and then download, install and run the devkit
I'm running Snow Leopard, and installed a custom built Ruby according to the guide here: http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard . My ruby binary lives in usr/local/bin/ruby and my gems are installed in /usr/local/bin/gem . My gem env looks like so:
RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
I think I may have borked the install since all actions taked on gems give the error:
ERROR: While executing gem ... (Errno::EEXIST)
File exists - /usr/local/bin/ruby
How do you edit the environment variables for the gem environment?
And for those of you on OS X and using ruby AND gems, what did you use to get yourself up and running?
I'm thinking of just nuking everything and starting anew.
It looks like your installation of ruby into /usr/local/bin is not the ruby that you're getting, which probably means /usr/local/bin/ is not in your PATH. If you'd like to run that ruby, try editing your .bash_profile to add /usr/local/bin like this:
export PATH=/usr/local/bin:$PATH
Alternately, you can add the path to a file in /etc/paths.d, which is the preferred method for adding paths globally on an OS X system.
I've tried things about three different ways, each with varying results. I have systems with the default install (/usr/bin), hand-built /usr/local/bin and also Mac Ports in /opt/local/bin.
By far, the simplest is to just use the built-in binary, which on 10.6.2 is ruby 1.8.7. In that scheme, gems are installed in /Library/Ruby/Gems. Second simplest is MacPorts (sudo port install ruby), third is the totally from source method you're describing above. Certainly there are good reasons people install from source, but unless you're trying to run ruby 1.9 or another version, you're best off using the built-in ruby 1.8.7.
Does the command "gem env" not report any gem paths? Mine reports a number of gem paths along with teh version of rubygems etc. that yours does not appear to be doing.
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/steveweet/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
You can edit the environment variables associated with gem by specifying them in your shell startup files, (.bashrc for bash). The relevant variables are all listed in the environment page of the gem web site. You will want to pay particular attention to GEM_HOME and GEM_PATH. You can check the current settings of these by typing echo $GEM_HOME at a shell profile
I would suggest that your best action at this moment in time may be to go back to your default ruby installation as provided with OS/X and then download and install rvm (The Ruby version manager) and then watch Ryan Bates screencast
What should I do before upgrading to the latest version of Ruby? any tips?
Update
sorry for my unclear question.
my condition: I've upgraded my Ruby from 1.8.7 to 1.9.1p243. It makes me can not use all installed gems.
so, what should I do before upgrading Ruby? uninstall all my installed gems? I was looking in other SO posts in here, But there are no answers for my question.
Unless you are using custom GEM environment variables or a .gemrc (or some multi ruby system like rvm) then the locations where rubygems are installed for each ruby installation will be different.
You can manage the locations used by rubygems by managing the GEM_HOME and GEM_PATH environment variables or the .gemrc file. It is possible to set your gems to be shared across ruby installations with these variables or the .gemrc
.gemrc:
http://docs.rubygems.org/read/chapter/11
GEM Environment variables:
http://docs.rubygems.org/read/chapter/12#page52
You can find the environment settings for a rubygems installation by running:
/path/to/gem env
This will output something like the following:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.4
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.0.0]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- /home/aji/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gemcutter.org
While the number of rubygems that are compatible with ruby 1.9 is constantly growing, you will need to check with the maintainer or homepage of each gem/project to verify if your gems will work or not.
Also check previous questions on SO regarding differences between 1.8 & 1.9:
What is the difference between Ruby 1.8 and Ruby 1.9