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.
[root@machine1 ~]# gem install backup Building native extensions. This could take a while... ERROR: Error installing backup: ERROR: Failed to build gem native extension. /opt/rh/ruby193/root/usr/bin/ruby extconf.rb mkmf.rb can't find header files for ruby at /opt/rh/ruby193/root/usr/share/include/ruby.h Gem files will remain installed in /opt/rh/ruby193/root/usr/local/share/gems/gems/atomic-1.1.14 for inspection. Results logged to /opt/rh/ruby193/root/usr/local/share/gems/gems/atomic-1.1.14/ext/gem_make.out
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:
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
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.
gem install backup
The only problem I have now is that when I try to run backup I get the following:
[root@machine1 ~]# backup -bash: backup: command not found
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.
echo "pathmunge /opt/rh/ruby193/root/usr/local/bin" | sudo tee -a /etc/profile.d/ruby193.sh
This is the same for any gems you install that need building. Once you’ve done the above gem install somegem commands will work.