1

I have Ruby 1.8 and Ruby 1.9.1 on my Ubuntu operating system. When I do a gem install php_http_build_query, it installs the gem to Ruby 1.8. How do I get it to install it to Ruby 1.9.1?

5 Answers 5

1

Preface RVM (Ruby Version Manager) might be the best long term alternative.

I believe I know your scenario because I have been there before when using Ubuntu 12.04. Before anything, after jumping through these hoops I learned the best way to manage Ruby on a system is to use RVM (Ruby Version Manager). It‘s not a part of the official Ubuntu/Debian package manager setup, but if you are serious about Ruby development, RVM is the best way to go to setup and use multiple versions of Ruby without conflict.

But if you simply are using Ruby 1.9.1 and just want that to be recognized as the default Ruby version, do the following.

That said, if you are on a setup where RVM won’t fit your needs or you prefer to stay with Ruby 1.9.1, read on…

So I’m going to assume you installed Ruby 1.8 via the default repository in Ubuntu 12.04 and then—after the fact—realized you needed Ruby 1.9.1 so you installed it via a command like this:

sudo aptitude install ruby1.9.1 ruby1.9.1-dev \
                      rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \
                      build-essential libopenssl-ruby1.9.1 \
                      libssl-dev zlib1g-dev

Well, that will get Ruby 1.9.1 installed on your system but it won’t make Ruby 1.9.1 the default. The key to getting this set is to use update-alternatives and as the official update-alternatives man page explains:

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice for an editor to invoke if the user has not specified a particular preference.

Debian’s alternatives system aims to solve this problem. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name.

So in this case there are three steps you need to take to get Ruby 1.9.1 properly recognized as the default Ruby on the system.

First, run this command:

sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
                         --slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz \
                                   /usr/share/man/man1/ruby1.9.1.1.gz \
                         --slave   /usr/bin/ri ri /usr/bin/ri1.9.1 \
                         --slave   /usr/bin/irb irb /usr/bin/irb1.9.1 \
                         --slave   /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1

Next, run update-alternatives again to choose your Ruby interpreter. This also changes symbolic links for core Ruby items:

sudo update-alternatives --config ruby

Make your selection and then move onto the update-alternatives for related Ruby GEMs:

sudo update-alternatives --config gem

Finally, confirm the version of Ruby has been updated like this:

 ruby --version
1

Use absolute path to install the specific version of gem to a specific version of ruby. eg /opt/sensu/embedded/bin/gem install vmstat.

ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

/opt/sensu/embedded/bin/ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

Even though my default version is ruby 1.9.3p392, I can install gems specific to ruby 2.3.0p0.

0

Not the best solution, but I’m in a rush. I went into the /var/lib/gems/1.8/gems/ folder and copied the contents over to /var/lib/gems/1.9.1/gems folder. I didn’t have a gems folder in the 1.9.1, so I had to manually create it.

0

Gem command is linked to the Ruby version installed.

Gem for Ruby 1.8 is different from gem for ruby 1.9.

So, if your path is pointing to 1.8, the gem command will install the gem in path respective to 1.8.

Solution: Quick and simple way is to Change the ruby path in environment variable to 1.9 and do gem install.

Note: If you need Ruby 1.8 then you need to change the path again. Also the gem has to be installed for each Ruby version separately in the above mentioned way.

0

The gem commands also come with a per-version filename. Take a look at this package for example: It contains gem1.8. That means you can target the Ruby version you want, independent of what’s the system default Ruby version.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .