views:

871

answers:

6

I am trying to install the ibm_db gem so that I can access DB2 from Ruby. When I try:

sudo gem install ibm_db

I get the following request for clarification:

Select which gem to install for your platform (i486-linux)
 1. ibm_db 0.10.0 (ruby)
 2. ibm_db 0.10.0 (mswin32)
 3. ibm_db 0.9.5 (mswin32)
 4. ibm_db 0.9.5 (ruby)
 5. Skip this gem
 6. Cancel installation

I am always going to be installing the linux version (which I assume is the "ruby" version), so is there a way to pick which one I will install straight from the gem install command?

The reason this is a problem is that I need to automate this install via a bash script, so I would like to select that I want the "ruby" version ahead of time.

+1  A: 

Try this:

sudo gem install --platform ruby ibm_db

Note that you can get help on the install command using:

gem help install


UPDATE: Looks like this option only works for RubyGems 0.9.5 or above.

John Topley
Clarification: It doesn't work on Ubuntu which uses 0.9.4 rubygems (in the repos), but it appears this may be a feature of later versions of rubygems.
Mike Stone
A: 

@John Topley

I already tried gem help install, and --platform is not an option, both in help and in practice:

$ sudo gem install ibm_db --platform ruby
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --platform


UPDATE: The Ubuntu repos have 0.9.4 version of rubygems, which doesn't have the --platform option. It appears it may be a new feature in 0.9.5, but there is still no online documentation for it, and regardless, it won't work on Ubuntu which is the platform I need it to work on.

Mike Stone
Which version of RubyGems are you on? I just tried it on Mac OS X using RubyGems v1.2.0 and didn't get that error.
John Topley
The newest version installed from apt-get install rubygems on Ubuntu... also see: http://www.rubygems.org/read/chapter/10#page33 (No --platform specified in the rubygems online documentation)
Mike Stone
What's the output from gem -v?
John Topley
0.9.4, which is what ubuntu repositories have... regardless the rubygems website itself doesn't list your option...
Mike Stone
It appears to be in the next version beyond what Ubuntu repos have
Mike Stone
Online documentation may not always be up to date. You can update RubyGems itself to the latest version using sudo gem update --system
John Topley
I prefer to let my packaging system (apt-get) deal with the updates, but thanks ;-)
Mike Stone
+2  A: 

You can use a 'here document'. That is:

sudo gem install ibm_db <<heredoc
  1
heredoc

What's between the \<\<\SOMETHING and SOMETHING gets inputted as entry to the previous command (somewhat like ruby's own heredocuments). The 1 there alone, of course, is the selection of the "ibm_db 0.10.0 (ruby)" platform.

Hope it's enough.

paradoja
This is the solution that works for rubygems version 0.9.4... check your gems help install to see if there is a --platform option.
Mike Stone
A: 

Try this, I think it only works on Bash though

sudo gem install ibm_db < <(echo 1)
Josti
Hmm, interesting... though piping echo output may work as well...? IE sudo gem install ibm_db | echo "1"
Mike Stone
A: 

Versions of Rubygems from 1.0 and up automatically detect the platform you are running and thus do not ask that question. Are you able to update your gems to the latest?

$ sudo gem update --system

Be warned if you are on Windows once you have updated; you might run into this issue.

Charles Roper
Thanks, but I prefer to use my packaging system to update my applications (ie, apt-get since I am on Ubuntu) :-)
Mike Stone
A: 

Another option is to download the .gem file and install it manually as such:

sudo gem install path/to/ibm_db-0.10.0.gem

This particular gem was at rubyforge.

Mike Stone