How to fix gem install error
Problem:
You are trying to install a Ruby gem but installation is failing with an error something like this,
Failed to build gem native extension
Most likely cause of these errors is missing build dependencies. Let’s dig into a couple of solutions.
Solution:
First make sure you have these minimum prerequisites installed on your system,
sudo apt-get install ruby-full build-essential zlib1g-dev
Next I’ll give you an example on how you can search and install missing build dependencies for a particular case.
Let’s say I’m’ trying to install the gem
gem install sass
Building native extensions. This could take a while...
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.2 -r ./siteconf20180217-38265-1l6kefu.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... no
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
creating extconf.h
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
Running autoreconf for libffi
/var/lib/gems/2.2.0/gems/ffi-1.9.21/ext/ffi_c/libffi/autogen.sh: 2: exec: autoreconf: not found
make: *** ["/var/lib/gems/2.2.0/gems/ffi-1.9.21/ext/ffi_c/libffi-x86_64-linux-gnu"/.libs/libffi_convenience.a] Error 127
make failed, exit code 2
In the above output what you need to look for is the lines ending with a
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... no
checking for shlwapi.h... no
First two lines have the same header file
How do we find these packages? Well, the solution mentioned here is for Debian but can easily be adopted for other distributions.
Open the Debian package content search page,
In the Keyword field enter
From the search result page we can see that
sudo apt-get install libffi-dev mingw-w64-i686-dev
Now
You can adopt this approach to identify missing dependencies and find the relevant packages providing those dependencies.
Cheers!!!