Saturday, April 12, 2014

How to install ruby gems in openSUSE

Some ruby gems are packaged for openSUSE, but often the packages are out of date or simply missing. Apparently, most people use the "Ruby Way" of installing gems. But. . . what is that and how to apply it in openSUSE?



For the sake of example, let's say I want to install Jekyll on my openSUSE 13.1 system. So I try this:
# gem install jekyll
Fetching: liquid-2.5.5.gem (100%)
Successfully installed liquid-2.5.5
Fetching: fast-stemmer-1.0.2.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing jekyll:
        ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.0 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib64/ruby/include/ruby.h


Gem files will remain installed in /usr/lib64/ruby/gems/2.0.0/gems/fast-stemmer-1.0.2 for inspection.
Results logged to /usr/lib64/ruby/gems/2.0.0/gems/fast-stemmer-1.0.2/ext/gem_make.out
#

This doesn't seem to work. What next? The thought came to me: "maybe there's a ruby-devel package that I'm missing". Sure enough:
# zypper if ruby-devel
Loading repository data...
Reading installed packages...


Information for package ruby-devel:
-----------------------------------
Repository: openSUSE-13.1-1.10
Name: ruby-devel
Version: 2.0-5.1.2
Arch: x86_64
Vendor: openSUSE
Installed: No
Status: not installed
Installed Size: 0 B
Summary: Development files to link against Ruby
Description: 
Development files to link against Ruby.
#

But I'm not a Ruby developer -- why should I install ruby-devel?? Putting this question aside, I just install it:
# zypper in ruby-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 4 NEW packages are going to be installed:
  fdupes ruby-common ruby-devel ruby20-devel 

4 new packages to install.
Overall download size: 2.9 MiB. After the operation, additional 17.6 MiB will be used.
Continue? [y/n/? shows all options] (y): 
Retrieving package fdupes-1.50-4.1.2.x86_64                  (1/4),  18.5 KiB ( 32.5 KiB unpacked)
Retrieving: fdupes-1.50-4.1.2.x86_64.rpm ...................................................[done]
Retrieving package ruby-common-3-89.2.noarch                 (2/4),  12.5 KiB ( 15.4 KiB unpacked)
Retrieving: ruby-common-3-89.2.noarch.rpm ..................................................[done]
Retrieving package ruby20-devel-2.0.0.p247-3.15.1.x86_64     (3/4),   2.9 MiB ( 17.6 MiB unpacked)
Retrieving: ruby20-devel-2.0.0.p247-3.15.1.x86_64.rpm ..........................[done (5.9 MiB/s)]
Retrieving package ruby-devel-2.0-5.1.2.x86_64                 (4/4),  10.1 KiB (    0 B unpacked)
Retrieving: ruby-devel-2.0-5.1.2.x86_64.rpm ................................................[done]
(1/4) Installing: fdupes-1.50-4.1.2 ........................................................[done]
(2/4) Installing: ruby-common-3-89.2 .......................................................[done]
(3/4) Installing: ruby20-devel-2.0.0.p247-3.15.1 ...........................................[done]
(4/4) Installing: ruby-devel-2.0-5.1.2 .....................................................[done]

While I'm at it, I install the devel_basis pattern containing important stuff like gcc, make, etc. that are needed by gem install (among others):
# zypper in -t pattern devel_basis
... lots of output ...

And try the gem install command again. This time it downloads and installs all the dependencies:
# gem install jekyll
... lots of output ...
20 gems installed
#

Great, so I try to run the program:
# jekyll
If 'jekyll' is not a typo you can use command-not-found to lookup the package that contains it, like this:
    cnf jekyll
#

Darn. So close, but yet so far. Applying my prodigious powers of intuition, I try the following at random:
# which jekyll2.0
/usr/bin/jekyll2.0

Aha! And this:
# jekyll2.0 --help
... lots of output ...

2 comments:

  1. Thanks for this, man - I've been having a helluva time getting Jekyll installed and this guide was EXACTLY what I needed. Short, sweet, and to the point.

    ReplyDelete
  2. the same problem i was, thanks and i rename my file from jekyll.ruby2.1 to jeryll for simple usability.

    ReplyDelete