In my previous article I outlined how to get Ruby installed via RedHat Software Collections (SCL) and this works for basic ruby commands until I tried to install my backup gem. I got an install error when trying to build the native extensions. This guide will show you how to install gems when using ruby via software collections.
<br /> [root@machine1 ~]# gem install backup<br /> Building native extensions. This could take a while...<br /> ERROR: Error installing backup:<br /> ERROR: Failed to build gem native extension.<br /> /opt/rh/ruby193/root/usr/bin/ruby extconf.rb<br /> mkmf.rb can't find header files for ruby at /opt/rh/ruby193/root/usr/share/include/ruby.h<br /> Gem files will remain installed in /opt/rh/ruby193/root/usr/local/share/gems/gems/atomic-1.1.14 for inspection.<br /> Results logged to /opt/rh/ruby193/root/usr/local/share/gems/gems/atomic-1.1.14/ext/gem_make.out<br />
I will need to install the relevant development tools to get this working. When installing ruby using other methods some how-to’s tell you to do the blanket install of all development tools. I want to make sure I run as lean an OS image as possible. So I will only install the required packages by running the following:
</p> <p>sudo yum install gcc gcc-c++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel ruby193-ruby-doc ruby193-ruby-devel ruby193-build<br />
I now have everything I need to get gem to build the native extensions. So I run the command to install backup again and everything succeeds.
</p> <p>gem install backup</p> <p>
The only problem I have now is that when I try to run backup I get the following:
<br /> [root@machine1 ~]# backup<br /> -bash: backup: command not found<br />
This is because the gem was installed inside of the software collections path so we will need to add this path to our existing path.
</p> <p>echo "pathmunge /opt/rh/ruby193/root/usr/local/bin" | sudo tee -a /etc/profile.d/ruby193.sh</p> <p>
This is the same for any gems you install that need building. Once you’ve done the above gem install somegem commands will work.