Uninstalling gems installed by me from default and global gemsets - ruby

I have installed a lot of gems in the default and global gemsets by mistake. I want to remove all gems that were installed in those gemsets by me. Is there a way do to this?

If you are using RVM and want to remove all the gems installed there, you can use
rvm gemset empty <gemset>
This will basically remove all gems from the gemset you specify, then you'll have a blank slate to start over installing things that you only care about.

Related

'require' not working with rvm

The following code lives inside my rails app's root folder and daemonizes/runs myserver.rb.
# myserver_control.rb
require 'rubygems'
require 'daemons' # causes 'no such file to load -- daemons' error since gem reinstall with rvm
#options = {
# options defined
}
Daemons.run('myserver.rb', #options)
It was working just fine until I installed rvm and now it can't seem to find the daemons gem. I have a feeling maybe the above is searching for the daemons gem in a system wide folder somewhere? Instead of being able to use the rvm installed daemons gem? How do I install the daemons gem on a system level where it can find it? OR how do I make it so it can find the rvm installed gem?
Currently I do not even have a 'system' gem set. How would I install gems on the system level after having already installed rvm?
If wishing to use the system ruby and gems you can type in
rvm use system
which will allow to use the system installed ruby and gems, but I think this kinda of defeats the purpose of using RVM I would instead install a default ruby in RVM and install any gems into that. To set a default Ruby after you have installed it, type this
rvm --default use 1.9.2
Edit
Based on comment your problem lies with running sudo, this creates a new subshell and different instance of rvm
RVM uses a concept of gemsets, which are unique groups of gems that you can use, most often specific to ruby versions (although you can make them specific to applications or global).
RVM will change your GEM_HOME when changing ruby versions, which tells ru ygems where your gems are installed. So when you installed RVM, you created a new blank gemset and RVM told rubygems to use that.
This is because gems are not always cross compatible between rubygems.
However, if you just writing rails apps, you should ignore the above for now and use bundler. Place 'gem "daemon"' I am your Gemfile and run bundle update from your app root directory.
Bundle helps you maintain gems on a per app basis, which means your app won't break if you upgrade a gem somewhere else. Using it and knowing how it works is best practices. Good luck.

How to make upstart work gracefully with RVM?

I have a simple Thin webserver I want to start with Upstart. However, upstart needs to be run with sudo which can't see all the RVM gems like Thin. rvmsudo hasn't helped me either. What's the solution for upstart to see your RVM gems?
RVM is really more for personal use. For a system service, I would just install the version of Ruby you want (someplace that doesn't conflict with the system version, like /usr/local/) and use Bundler in deployment mode to get the gemset.
Have you considered creating a gemset and defaulting to a particular gemset for your project?
Default to a Ruby: rvm use 1.9.3
Create a Gemset Manually (One time): rvm gemset create
project-name
Switch to this Gemset: rvm gemset use project-name
See if this works, you might be able to later on add this to your .rvmrc file for automatic context switching. But give it a shot first and see if this works.

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.

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

How to manage multiple gemsets and ruby versions with RVM?

I am really confused by the explanations given in RVM website. The relation between different ruby interpretors and gemsets are not clear to me. According to me, it is like this -
My Account in my Mac have one rvm
That rvm installs and manages set of different versions of ruby interpretors.
each ruby version has set of gemsets.
Am i getting things clear... Any more amount of explanations are welcome. I am in a position to work on (Ruby 1.8.7 + rails 2.3.8 and its dependencies) and (Ruby 1.9.2 and Rails 3.0 and its dependencies)...
If any one is well versed with handling many ruby versions and gemsets with the help of rvm, please explain to me... thanks for the help
Here is how I like to do it...
Install a ruby with RVM
Switch to/use that ruby
Create a gemset for a project
Switch to/use that gemset
Install gems needed
create an alias that points to my chosen ruby & gemset
switch to/use that new alias (again, associated w/ a project)
Do this as many times necessary for your different projects that you want to keep separate from eachother.
Example:
$ rvm install ruby-1.9.2
...
$ rvm list
rvm rubies
=> ree-1.8.7-head [ i386 ]
ruby-1.9.2-head [ i386 ]
ruby-1.9.2-preview3 [ i386 ]
$ rvm use ruby-1.9.2-preview3
info: Using ruby 1.9.2 preview3
$ rvm gemset create my_project
info: Gemset 'my_project' created.
rvm gemset use my_project
info: Now using gemset 'my_project'
$ gem install httparty
When you HTTParty, you must party hard!
Successfully installed crack-0.1.8
Successfully installed httparty-0.6.1
2 gems installed
$ rvm alias create my_project ruby-1.9.2-preview3#my_project
info: Creating alias my_project for ruby-1.9.2-preview3#my_project.
info: Recording alias my_project for ruby-1.9.2-preview3#my_project.
$ rvm use my_project
info: Using ruby 1.9.2 preview3 with gemset my_project
$ ....
Now I have an entire environment dedicated to a particular project. This is great because I can experiment with all sorts of different gems/versions without worrying about stomping all over other projects that have very specific requirements.
Good luck!
To add onto Brian's answer above, you can also use .rvmrc files to dynamically switch gemsets when entering new project directories.
simply run the following:
rvm rvmrc create ruby-1.8.7-p358#my_project
This will help stop confusion which I had when switching and forgetting to change gemsets
UPDATE
.rvmrc files are in the process of being dropped for the newer .ruby-version file
see discussion here: https://gist.github.com/fnichol/1912050

Resources