How to make ruby gems available to all users? - ruby

I installed a Ruby gem running this command from root:
gem install pushmeup
The gem works well when executing scripts from root. When I try to execute a script from non-root user, I see this error about such gem not found:
/usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- pushmeup (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from pushAPNS.rb:2:in `<main>'

Edit:
RVM gives you compartmentalized independent ruby setups. This means
that ruby, gems and irb are all separate and self-contained - from the
system, and from each other.
https://rvm.io/gemsets/basics
============
Never use sudo with rvm.
Type rvm gemset list
Type rvm gemset use global
Type gem install some_gem
The gems in the global gemset will be available in all other gemsets. If you want to create a gemset for a specific project, then do:
rvm gemset create proj1_gems
rvm gemset list
rvm gemset use proj1_gems
To delete a gemset:
rvm gemset delete proj1_gems
rvm gemset list
Each version of ruby has its own gemsets. You can switch to a specific ruby version and one of the gemsets for that version with one command like this:
rvm use 2.0.0#proj1_gems
But generally, I do:
rvm use 2.0.0
rvm gemset list
rvm gemset use some_gemset_name_in_the_list

Related

How do RVM rubies find gems?

I'm using Ruby 1.8.6 under RVM on Mac OS X (10.9.2). I installed everything as a local user (not root), and then installed a gem using:
gem install gli -v 1.6
When I run a ruby with require('gli'), I get the error:
in `require': no such file to load -- gli (LoadError)
even though gem list shows gli (1.6.0).
I don't know exactly how RVM does its gemsets, but there is no gli.rb file in any of the directories in the $LOAD_PATH.
How does RVM interact with the $LOAD_PATH to find the necessary gems in the gemset?
Try adding a require 'rubygems' at the top of your source file. In 1.8 rubygems aren't required by default.
Thus said, regarding gem paths:
GEM_HOME indicates where gems are installed. To find out what it is for your case do:
$ echo $GEM_HOME
This should display an RVM-related path, since RVM changes this environment variable in order to make the $ gem install command install gems in its directories.

What's the difference between ruby-1.9.3-p194 and ruby-1.9.3-p194#global gemsets?

I am currently running the following on OSX 10.6.8 and am trying to understand gemsets and gems.
Ruby 1.9.3-p194
Rails 3.2.8
RVM 1.15.6
When I look in .rvm/gems/ I see several gemset directories. Inside each one there is a gems directory. Now, whats the relationship between the non-'#' gemset and the #global gemset?
From the documentation:
Interpreter global gemsets
RVM provides (>= 0.1.8) a #global gemset per ruby interpreter.
Gems you install to the #global gemset for a given ruby are available
to all other gemsets you create in association with that ruby.
This is a good way to allow all of your projects to share the same
installed gem for a specific ruby interpreter installation.
To expand on this, the gemset without the #global is the default gemset for that Ruby version. It is essentially a gemset with no name. The #global gemset, however, is special for the reasons outlined in the docs above.

When I run 'gem list' from within any of my projects I get the following output

user#user:~/Workspace/fq$ gem list --local
*** LOCAL GEMS ***
bundler (1.0.21)
Why isn't it showing all the gems I have installed?
Are you using rvm? If so, those gems might be installed under different gemsets.
Run rvm gemset list to display all gemsets.
Run rvm gemset use #{gemset_name} to use this gemset_name,
then run gem list again.

RVM global gemset confusion

I'm using a gemset per project approach. Suppose I just installed RVM, created a gemset, called 'test' and install rails 3.1.0.rc4 there, which installs a bunch of gems. Now I switch to the global gemset (rvm gemset use global), and view my gems. I expect to see empty list, because I didn't install any gems into global gemset, but see all my gems from 'test' gemset. How is that?
My guess is that rvm gem list show all gems from all gemsets when invoked from global gemset. If so, how can I view only current gemset's gems?
In common:
rvm <ruby version>#<gemset name> do gem list
For example:
rvm #test do gem list
show that you want: gems on test gemset environment
Another way:
rvm use #test
gem list
show the same
Use gem list instead of rvm gem list
in RVM 1.16.0 the command gem is removed, it was causing to much confusion and was deprecated a year ago.
instead use:
rvm [<ruby>[#<gemset>],...|default|all] [--verbose] do <command> ...

rvm gemset copy error

I'm working out the details to move from ruby-1.8.7 to ruby-1.9.2 with rvm and I'm hitting an issue with copying gems from one ruby to another and I wanted to see if anyone knew what the deal is and why it my be erring.
I already have 1.9.2 installed, but running rvm gemset copy is throwing an error.
[22:11][adamstacoviak:~]$ rvm gemset copy ruby-1.8.7-p249 ruby-1.9.2-p180
Copying gemset from ruby-1.8.7-p249 to ruby-1.9.2-p180
cp: cannot overwrite directory /Users/adamstacoviak/.rvm/gems/ruby-1.9.2-p180/cache with non-directory /Users/adamstacoviak/.rvm/gems/ruby-1.8.7-p249/cache
Making gemset for ruby-1.9.2-p180 pristine.
ERROR: Error running 'rvm gemset pristine' under ,
please read /Users/adamstacoviak/.rvm/log/ruby-1.8.7-p249/gemset.pristine.log
... and here's the contents of the log file. I did update bundler as well since I saw that it mentioned bundler-1.0.12 was not found. Updating to bundler 1.0.12 didn't do the trick.
[2011-04-12 22:09:54] rvm gemset pristine # under ruby-1.9.2-p180
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::RemoteFetcher
Restoring gem(s) to pristine condition...
Cached gem for bundler-1.0.12 not found, attempting to fetch...
[2011-04-12 22:14:26] rvm gemset pristine # under ruby-1.9.2-p180
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::RemoteFetcher
Restoring gem(s) to pristine condition...
Cached gem for bundler-1.0.12 not found, attempting to fetch...
Any thoughts on why rvm gemset copy is erring?
RVM is your friend and already knows how to upgrade your versions:
rvm help upgrade
Usage:
rvm upgrade [source ruby] [destination ruby]
Description:
Upgrades the specified (already installed) source ruby given to the
given destination ruby version. Will migrate gemsets, wrappers, aliases
and environment files.
The process will prompt you at each stage - if the versions look incorrect,
please cancel and perform it manually.
Examples:
$ rvm upgrade 1.9.2-p136 1.9.2-p180
$ rvm upgrade ree-2011.01 ree-2011-02
Type rvm help ugrade at the command line.
Simply add the line to the file
/usr/bin/gem (may be different on a
mac) require 'rubygems/gem_runner'
after require 'rubygems'
Found this over here
You could just use cp:
cp -R ~/.rvm/gems/ruby-1.8.7-p249/* ~/.rvm/gems/ruby-1.9.2-p180/

Resources