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

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/

Related

Ruby Gems getting out of hand

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

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.

What are the advantages of RVM on linux?

Please understand that I'm not trying to bash RVM. I would just like to understand why it's so popular in the Ruby community.
There appears to be two main reasons to use RVM - to manage/switch between different versions of Ruby, and to manage a specific gemset per project. However there seem to be much cleaner ways of achieving the same thing on linux:
I can install different ruby versions
from the repositories through the
regular package manager, or build
from source and install as a package.
I can switch between versions using
update-alternatives (on Debian, Ubuntu, Fedora at least).
I can use Bundler to manage sets of
gems for different projects, as
outlined in this blog post.
Given the above, I'm confused as to why I would want to use RVM to manage Ruby versions and gems. The idea of using a bash script to install software on my system outside the package manager feels very hackish, a feeling backed up by this blog post.
Not being a Mac user I am totally guessing here, but I thought it might be that OS X is very popular in the Ruby community. If there is no system like update-alternatives for switching ruby versions on OS X, RVM might be the best solution and this idea has carried over to linux too.. like I said, this is just a guess.
So why is RVM so popular, and why should I prefer it over the regular package manager + Bundler on Debian or Ubuntu?
If you need to manage many project with diferent versions of Ruby and special Rails like me (I have 3 project to manage wich uses Rails 2.3.5, Rails 3.0.5 and Rails 3.1 rc1) do RVM is nessesary solution. As you may know Rails 2.3.x has no bundler support and uses old gems so version managing is the way to make developing easier. I hope I helped you alittle.
RVM is portable
update-alternatives works globally, RVM works in shell/script context - I suppose it is modyfying env paths. Now imagine having two apps on one server: one 1.8.7 and another 1.9.2
Usage of Ruby EE requires manual installation - with RVM it is matter of one command to install it.
I had too much problems with mixed gem dirs with 1.8.7 only or 1.9.2 only gems in Debian.
Easy backup - just copy .rvm dir.
Consistent clustering (same platform) - just share one .rvm dir.

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.

Resources