RVM global gemset confusion - ruby

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> ...

Related

How to make ruby gems available to all users?

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

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: How to use gems from a different ruby?

I have been using RVM to manage my Rubies and gems.
When I first installed RVM, the Ruby version that I installed was 1.9.2-p0. I recently installed Ruby 1.9.2-p136, which created a new Ruby in the RVM.
My problem is I want to use the latest version of Ruby but all of the gems I installed were installed under the 1.9.2-p0 directory, because RVM keeps gems completely separate between Rubies, and I want to be able to use those gems with my new version, p-136 without having to reinstall them all.
Is there a way I can get my gems from my p-0 Ruby to work with my p-136 Ruby?
You can use copy in rvm
$ rvm gemset copy 1.9.2-p0 1.9.2-p136
See more about the rvm copy command
This is the fastest way to get your gems moved over and it wont reinstall everything, just copy them over. But once you've got that squared away I'd do as the others are suggesting and start using gemsets. It's a nice way to group the gems you use in your projects.
This might help: http://rvm.io/gemsets/initial/
Basically, if you setup a global gemset configuration, those gems will be used for every ruby version you install.
You need to check out gemsets and export your current gems.
rvm gemset export
Read the gemset docs for more information.
You can copy a gemset from one ruby to another.
rvm copy
$ rvm gemset copy 2.1.1#rails4 2.1.2#rails4

RVM: Uninstalling all gems of a gemset

I have global gems and various gemsets. I want to remove all gems of a gemset. Is there a way do to this, besides uninstalling the gemset?
Use the gemset empty command:
rvm gemset empty mygems
This command removes all the ruby gems installed locally in 1-step
Works well in Ubuntu 10.10
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
PS - removes all local gems. Use sudo accordingly.
you can also use rvm --force gemset empty
rvm gemset empty <gemset name>
This will remove all gems from your mentioned gemset.
rvm gemset empty <gemset> works, but only if you specify a gemset name.
If you want to empty the default gemset, you need to pass an empty string for the gemset name.
rvm gemset empty mygems ""
Isn't removing all the gems out of a gemset essentially the same operation as deleting a gemset and then adding it back? Why not just do this:
$ rvm gemset mygemset
$ rvm gemset delete mygemset
$ rvm gemset create mygemset
This is the safest way to uninstalling all gems of a gemset
Step 1
If you gem version is less then 2.1.
gem update --system
gem --version
Step 2
gem uninstall --all
references

Resources