Ruby Gems getting out of hand - ruby

So I've recently been having a lot of trouble with my Ruby gems, such as: not being able to uninstall them because they're set to "default", my Bundler version showing as 2.2.9 even after I've uninstalled it, 2.2.9 being installed in the 2.2.7 directory, seeing "bundler" in 3 different directories on my machine, etc.
I would like to:
a) start from scratch by deleting ALL gems and gem folders on my machine (haven't found a way to do that)
b) prevent this from happening again (basically advice)
Some guidance on this would be VERY much appreciated.

If you're using rbenv you should find all versions in ~/.rbenv/versions by default (whatever $RBENV_ROOT refers to), and can delete them there.
Depending on OS you may also have a system Ruby installed, which you probably shouldn't mess with.

constant
RUBY_VERSION
"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
or
RUBY_DESCRIPTION
or gem env

Related

Ruby, Versions, Gems, Versions and more, Oh My

Apologies for the topic title, couldn't resist.
Basically, For no reason whatsoever apart from trying out different things. I want to implode RVM and try out rbenv. Nothing against RVM, just want to try different peoples software and try different things out.
I can get rid of RVM and install rbenv no problem. Could you guys confirm a few things for me.
Firstly, if I do the above, and then install a few different ruby versions. I know I can place a .ruby-version file in a projects root directory to specify a specific ruby version but then when I say gem install <gemname> I take it that is installed globally for that ruby version.
If I then use bundler per project to manage what gems are used and I specify a gem version, what happens if the version specified in the lock file is different to the currently installed version and what happens if it's vice versa?
I just need a bit of clarification on what's doing what in regards to ruby, versions, gems and their versions.
One of the (many) lovely things about rbenv is that you can so easily look right at your ruby installation to see what's going on. For example, on my machine I can open ~/.rbenv and there's versions containing my ruby installations, such as 1.9.3-p327. Opening that, I can keep drilling down to see my gems installed for that version of ruby (in ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems). It is then trivial to run gem list or gem install somegem and confirm that what's being affected is this very collection of gems - if this is the current ruby (set in rbenv global and starred in rbenv versions).
In short, everything about your system thinks that ruby means this version of ruby and that its library is this library.
For Bundler, you'll need to install rbenv-bundler. A nice tutorial (easily found with Google) is here: http://dan.carley.co/blog/2012/02/07/rbenv-and-bundler/

Multiple installs of Ruby -- how to solve in OS X

I'm having problems with Ruby scripts finding the right gems. It seems this is related to having multiple installs of Ruby on my system. OS X already comes with Ruby but it's not the latest one. I upgraded from Snow Leopard to Lion and suddenly have all these instances of the rubygems folders:
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems
/Library/Ruby/Gems/1.8/gems/rubygems-update-1.8.11/lib/rubygems
/Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/1.9.2/rubygems
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems
/Users/[user_name]/.rvm/repos/ruby/lib/rubygems
I installed the graph gem with gem install and I can't seem to find it in any of these locations. irb finds it when I do a require but a ruby script saved and run from the CLI produces the error:
'require': no such file to load
Another clue is that when running rails server I often see output from /Library/Ruby/Gems/1.8/gems/
But the graph gem doesn't seem to be in that path either.
So, yes a big mess. Any help to safely simplify this and remove the redundant instances would be greatly appreciated.
Update:
Was able to track the installed gems to:
/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/lib/ruby/user-gems/1.8/gems
So should I just delete everything else with a rm -rf? I'd hate to do that and cause all sorts of dependency problems. Ultimately I'd like to end up with a clean system with only one ruby install but I cannot wipe out my hard drive.
I recommend you use rvm to switch rubies and gems. put a .rvmrc into your project folders and it will switch a "gemset" automatically for you.
The general consensus is to leave the ruby version of the os as it is an use either rvm or rbenv to switch ruby versions.
It does look like you have rvm installed as well as multiple ruby installation installed in different ways too.
Does rvm work correctly, if so you can ignore your other ruby installations.

Using RVM, how to ensure gems and non-gems see the same version of ruby?

I'm trying to install bdb on Ubuntu as a gem as follows,
gem install bdb
I'm not using sudo, since I am installing with rvm. The ruby version on my system is 1.9.1 but the version I'm using for this installation is 1.8.7 (I'm installing rbot, you see). The problem I've encountered is:
checking for db_version() in -ldb-4.something... no
I assume this means that rubygems is not finding ldb4.something in the places it is looking. Is this because I installed libdb-4.something (7, actually) using sudo, and my system's ruby version is different from the ruby version I'm using for bdb? Using rvm, how should I manage this sort of situation? Maybe I'm doing things wrong, but it seems to me that my problem is that not everything I'm using is a gem, and the stuff that isn't gems is seeing the wrong version of ruby.
(if it turns out that my problem is something completely unrelated: I am still interested in the question. How do things I've installed on my system with a particular version of ruby get along with gems installed using rvm under different versions of ruby?)
"How do things I've installed on my system with a particular version of ruby get along with gems installed using RVM under different versions of ruby?"
They don't, and that is the point. RVM is for managing different versions of Ruby so that they are isolated from each other.
This means that the Ruby versions that you use for system (when you do sudo gem install that would be installing to system) have nothing to do with the current environment (when properly set up.)
When you are in a RVM environment, each version of Ruby installed is an isolated environment.
What I would recommend is this:
Go to the RVM Website and check it out.
At the end of the page, continue with your reading about how to use gemsets.
go to your project directory
rvm use 1.8.7#your_project_environment
create your .rvrmc file so that you will automatically be using this environment in your project on the future visits to this project, this file can contain "rvm use 1.8.7#your_project_environment" which will achieve this.
install all required gems
If you have additional questions, feel free to visit Wayne E. Seguin and a ton of other users of RVM and we will be happy to help you out. Of course, the first search for answers is the documentation on the web site.

How do I retain installed gems after updating rubygems?

After a recent reinstallation of Ubuntu, I reinstalled RubyGems. The Ubuntu repository grabbed version 1.3.5. Later I found I need the latest version. So I installed the RubyGems update to get to version 1.3.7.
The trouble is, upon upgrading gem list returns only a small subset of all my originally installed gems. In the past, I've solved this by reinstalling all my gems following an upgrade, but this is troublesome and I hope to avoid this workaround now and in the future.
I tried adding an export GEM_HOME to my .bashrc file. It didn't work. gem list still doesn't list all my gems (even though I can find them on my computer in /var/lib/gems/1.8/gems. I also created a .gemrc yaml file and set the gemhome path. When I run gem env I can see that the home path is set, but still gem list doesn't return everything.
What's up with this?
This won't directly answer your question, but a lot of us use rvm to manage Ruby and gems. The benefit is it doesn't require us to mess with the system's Ruby installation and gems, leaving those alone for any OS routines needing a particular version of Ruby or a gem.
Since switching to rvm I've quit installing an updated version in /usr/bin/local too as rvm makes it so easy to keep my development versions separate from the system.
There are great reasons to tweak the system gems so I won't question why you might do so. I'm just tossing out the rvm thang as it might help solve your needs.

Why is Phusion Passenger refusing to recognize my updated RubyGems?

I've updated RubyGems everywhere I can possibly think to update it:
The various places I've updated RubyGems http://files.droplr.com/files/14167865/zel8k.Screen%20shot%202010-03-09%20at%2017:24:59.png
but Phusion passenger keeps throwing the same error:
Error Screenshot http://files.droplr.com/files/14167865/zee8W.Screen%20shot%202010-03-09%20at%2017:19:50.png
There is that one freaking place that shows 1.3.1 as the version, despite the file name of 1.3.6. I've obviously borked things up pretty badly here.
That is, I need to update to 1.3.2 or greater and that I currently have 1.3.1.
Any idea how in the world I can get PP to use the correct version of RubyGems and preferably change things so I don't have to face this problem again?
Could this have anything to do with different paths for RubyGems and Ruby environments? These are my environments:
Environment screenshots http://files.droplr.com/files/14167865/zfH6x.Screen%20shot%202010-03-09%20at%2019:07:18.png
First, obtain the value of your PassengerRuby configuration. Then use that Ruby interpreter to run the following script:
http://pastie.org/862871
Like this:
/path-to-your-passenger-ruby-interpreter myscript.rb
and follow the instructions.
That might be of several reasons.
First, verify that you don't have it to explicitly require the rubygem in environment.rb. That is, if you have a line like this:
config.gem "ruby_gems", :version => "1.3.1"
Then you'll have to remove the version from it.
Also, seeing that the rubygems-update gives the incorrect version, you might want to uninstall it.
sudo gem uninstall rubygems-update
Since you have updated it, that gem is not necessary anymore.
I don't think it will help, but I would probably uninstall the macports version of rubygem as well since that might create collisions, even though it doesn't seem like it in this case.
Update:
Since you are using the Ruby from the operating system you don't have to install rubygem through macports at all.
To remove it:
sudo port uninstall rubygems
After that, make sure that you have upgraded the correct rubygem (the binary shows correct, but perhaps there is something missing)
sudo gem update --system
After you've done that. Open up irb (that is, irb and not the rails console) and check the following:
require 'rubygems'
puts Gem::RubyGemsVersion
Also, if you could paste how your apache/nginx configuration looks like, I doubt there is anything wrong in there, but you never know.

Resources