rbenv and gems that require C extensions - ruby

So I'm trying to install the audite gem, but having issues with rbenv:
$ bundle install
Fetching gem metadata from https://rubygems.org/...
Installing audite (0.3.0)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/opt/boxen/rbenv/versions/1.9.3-p448/bin/ruby extconf.rb
checking for mpg123.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/boxen/rbenv/versions/1.9.3-p448/bin/ruby
please install mpg123 headers
Gem files will remain installed in /opt/boxen/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/audite-0.3.0 for inspection.
Results logged to /opt/boxen/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/audite-0.3.0/ext/mpg123/gem_make. out
An error occurred while installing audite (0.3.0), and Bundler cannot continue.
Make sure that `gem install audite -v '0.3.0'` succeeds before bundling.
I know that these gems require c extensions, and I have them installed with homebrew. And if I go into the cellar for homebrew I can see the file it's looking for (mpg123.h)
/opt/boxen/homebrew/Cellar/mpg123/1.15.4/include/mpg123.h
So, is there a way to add this into the rbenv environment without just sim-linking or copying it directly into /opt/boxen/rbenv/versions/1.9.3-p448/

xcode-select --install
resolved it for me.

I ran into the same issues trying to install audite. Turns out that mkmf writes a file call mkmf.log to tell you more specifically what it does to find out if the headers are availbale or not:
>>> cat mkmf.log
have_header: checking for mpg123.h... -------------------- no
"xcrun cc -E -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -o conftest.i"
xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.
checked program was:
/* begin */
1: #include <mpg123.h>
/* end */
--------------------
Turns out that I hadn't had xcode installed yet; after installing it and running
xcode-select --print-path
I saw that the path was now set. Then I still had to run xcrun once to agree to Apple's licence agreements, but then the installed installed just fine!

Add the homebrew include directory to your path, rubygems will find it. This isn't really a problem with rbenv.
In a default install, homebrew symlinks all the include folders of the packages to /usr/local/include, in your case, those should be in /opt/boxen/homebrew/include. Just have a look around, there should a be a folder somewhere containing all includes.

So in the end one of the following things fixed it for me, I'm not sure which because I'd rebuild and changed my machine few times since I had this issue:
Switched to Ruby 2.0.0
Upgraded to Mavericks (which does change some
stuff with xcode stuff I believe)
Updated my Boxen/Brew to latest
version

Related

gem install therubyracer -v 0.12.3 on OSX 10.15

I've followed the steps to install v8 and the libv8 gem. After that, I am unable to successfully install therubyracer 0.12.3. The mkmf.log chokes when trying to validate the v8.h header and throws out an unknown type name-error.
My environment:
Ruby: 2.6.3
OSX: 10.15
xcode-select: 2373
libv8: 3.16.14.19
v8:v8#3.15 (via Homebrew)
brew info v8#3.15 = v8#3.15: stable 3.15.11.18 (bottled) [keg-only]
g++: Apple clang version 11.0.0 (clang-1100.0.33.17)
I've worked through the suggestions here. Anyone got a suggestions?
Gem install
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8#3.15
Failure message
Building native extensions with: '--with-v8-dir=/usr/local/opt/v8#3.15'
This could take a while...
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.
current directory: /Users/kristinsmith/.gem/ruby/2.6.0/gems/therubyracer-0.12.3/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/Library/Ruby/Site/2.6.0 -r ./siteconf20200120-16109-4pdf22.rb extconf.rb --with-v8-
dir\=/usr/local/opt/v8#3.15
checking for -lpthread... yes
checking for -lobjc... yes
checking for v8.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-pthreadlib
--without-pthreadlib
--with-objclib
--without-objclib
--enable-debug
--disable-debug
--with-v8-dir
--with-v8-include
--without-v8-include=${v8-dir}/include
--with-v8-lib
--without-v8-lib=${v8-dir}/lib
/Users/kristinsmith/.gem/ruby/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in
`configure': By using --with-system-v8, you have chosen to use the version
(Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with
the libv8 rubygem.
However, your system version of v8 could not be located.
Please make sure your system version of v8 that is compatible
with 3.16.14.19 installed. You may need to use the
--with-v8-dir option if it is installed in a non-standard location
from /Users/kristinsmith/.gem/ruby/2.6.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in
`configure_makefile'
from extconf.rb:32:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/kristinsmith/.gem/ruby/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-
0.12.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/kristinsmith/.gem/ruby/2.6.0/gems/therubyracer-
0.12.3 for inspection.
Results logged to /Users/kristinsmith/.gem/ruby/2.6.0/extensions/universal-darwin .
19/2.6.0/therubyracer-0.12.3/gem_make.out
mkmf.log
...
find_header: checking for v8.h... -------------------- no
"xcrun clang I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.
5.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/v8#3.15/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -Wall -g -rdynamic -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -arch x86_64 -c conftest.c"
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
In file included from conftest.c:3:
/usr/local/opt/v8#3.15/include/v8.h:98:1: error: unknown type name 'namespace' namespace v8
{
^
/usr/local/opt/v8#3.15/include/v8.h:98:13: error: expected ';' after top level declarator
namespace v8 {
^
;
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <v8.h>
/* end */
--------------------
...
I had the same error, and finally it appeared that rbenv ruby version was ignored.
Running eval "$(rbenv init -)" solved the issue and therubyracer was installed correctly.
Many thanks for the help! The final solution turned out to be:
Installing rbenv
Setting a Ruby version (2.6.3) in rbenv
Adding the following lines to my .zshrc:
eval "$(rbenv init -)" (Thanks, Mykolas Kairys)
export LDFLAGS="-L~/.rbenv/versions/2.6.3/lib"
export CPPFLAGS="-I~/.rbenv/versions/2.6.3/include"

After upgrading to macOS Mojave gem update is failing

Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.3.0/gems/libxml-ruby-3.1.0/ext/libxml
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20180926-80978-eoqfjh.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
--with-xml2-config
--without-xml2-config
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
extconf failure: need libxml2.
Install the library or try one of the following options to extconf.rb:
--with-xml2-config=/path/to/xml2-config
--with-xml2-dir=/path/to/libxml2
--with-xml2-lib=/path/to/libxml2/lib
--with-xml2-include=/path/to/libxml2/include
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/libxml-ruby-3.1.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/libxml-ruby-3.1.0 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/libxml-ruby-3.1.0/gem_make.out
Updating nokogiri
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
The error is due to macOS Mojave has stopped placing the standard header files in /usr/include, keeping them only inside the XCode directory.
You can verify this by running ls /usr/include and most likely this directory does not exist anymore. On contrary, the usual trick by running xcode-select --install will not solve the problem.
The fix is to run legacy installer provided by Apple that will install the header files to /usr/include
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
If you are using homebrew, the recommended approach is to tell pkg-config where it can find the libxml2 library:
brew reinstall libxml2
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
Also, you may have outdated bundle config, which is in the way. Run bundle config build.nokogiri --use-system-libraries and it'll give you a warning and show what config you currently have. I was following all guides and reinstalled all gems and even ruby a few times only to find out that config was set to use a path that doesn't exist anymore.

Install SciRuby failed on OS X

I have gcc6.1 installed on OS X via brew, when I tried to install sciruby-full on my Mac, always got this Error:
>Fetching: nmatrix-0.1.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing sciruby-full:
ERROR: Failed to build gem native extension.
/usr/local/opt/ruby/bin/ruby -r ./siteconf20150627-98945-1pk3go6.rb extconf.rb
checking for apparent GNU g++ binary with C++0x/C++11 support... Exception `RuntimeError' at extconf.rb:144 - You need a version of g++ which supports -std=c++0x or -std=c++11. If you're on a Mac and using Homebrew, we recommend using mac-brew-gcc.sh to install a more recent g++.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/Cellar/ruby/2.2.2/bin/$(RUBY_BASE_NAME)
extconf.rb:144:in `<main>': You need a version of g++ which supports -std=c++0x or -std=c++11. If you're on a Mac and using Homebrew, we recommend using mac-brew-gcc.sh to install a more recent g++. (RuntimeError)
extconf failed, exit code 1
Gem files will remain installed in /usr/local/lib/ruby/gems/2.2.0/gems/nmatrix-0.1.0 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0/nmatrix-0.1.0/gem_make.out
My ruby and OS X is always the newest: Ruby 2.2.2 on updated Yosemite.
From your error message:
extconf.rb:144:in `': You need a version of g++ which supports
-std=c++0x or -std=c++11. If you're on a Mac and using Homebrew, we recommend using mac-brew-gcc.sh to install a more recent g++.
(RuntimeError)
Do the following (using homebrew)
brew tap homebrew/versions
brew install gcc48
if this does not work, try gcc47 or gcc46.
Note: It make take a while to build. gcc is quite large.

Error to install Nokogiri on OSX 10.9 Maverick?

I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects.
I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems.
The error is:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-libiconv-config
--without-libiconv-config
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:116:in `<main>'
Gem files will remain installed in /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9 for inspection.
Results logged to /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.9), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
I installed libxml2, libxslt and libiconv from Homebrew, and set the params to install Nokogiri, but don't work too.
I can't find what's wrong in my enviroment, can you help me?
You can also install Nokogiri on Mac OS X 10.9 Mavericks with full XCode Install using:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
Update
For those using Yosemite the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries
or, it might actually be in your MacOSX10.11.sdk folder (mine was as of 18-Sep-2015) anyways, so even if you are not yet fully up to El Capitan, I had recently updated XCode and you may need to use the El Capitan SDK path, which follows next:
Update
For those using El Capitan the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
Update
For those using Sierra the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
After navigating the animated GIFs here, all that I had to do was simply xcode-select --install and the gem install nokogiri worked fine.
I found this log and saw that gcc-4.2 was not found:
package configuration for libxslt
cflags: -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2
package configuration for libxml-2.0
cflags: -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxml2
package configuration for libiconv is not found
"/usr/bin/gcc-4.2 -o conftest -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libiconv/1.14/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/include -I/Users/ericcamalionte/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0"' -DNOKOGIRI_LIBXSLT_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26"' -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 conftest.c -L. -L/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libiconv/1.14/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/Users/ericcamalionte/.rvm/usr/lib -L. -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2 -lxml2 -lruby.1.9.1-static -lpthread -ldl -lobjc "
sh: /usr/bin/gcc-4.2: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
To solve this problem I intalled apple-gcc42 using homebrew brew install apple-gcc42 and created a symlink to my /usr/bin :
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc-4.2
If you're running Xcode 5.1, the command line tools don't work for nokogiri 1.6.1. You'll need to download the Late october 2013 tools from Apple. Once you do that run
sudo xcode-select -s /Library/Developer/CommandLineTools/
to set up your machine to use the Xcode 5.0.X command line tools, then run
gem install nokogiri
If you want to reset your command line tools to the Xcode.app version afterward run
sudo xcode-select -r
Or, another thing you can do is add the flag to ignore unknown command line arguments. Then the install looks like this:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri
This is what worked for me on OSX Mavericks:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -v '1.6.1' --verbose --no-ri --no-rdoc
I'm on OSX Mavericks and my problem turned out to be a bad install of Ruby.
So, I reinstalled ruby with rvm :
rvm remove ruby 2.0.0p451
rvm remove ruby-2.0.0-p451 && rvm install ruby-2.0.0-p451
I was then able to
gem install nokogiri --no-ri --no-rdoc
Problem solved.
I like to stick with system-provided stuff typically. This worked for me:
gem install nokogiri -- --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
I ran into this problem immediately after installing the Mavericks 10.9.5 update and the 10.9 Developer tools update from Apple. I ran xcode-select --install, but that did not fix the problem. Then I opened XCode, accepted the eula, and quit XCode. That fixed the problem.
I had this problem today, on Maverick, this is how I ended up solving the issue:
brew update
brew install libiconv
brew link libiconv
Make sure that you know the version of libiconv in Cellar mine below was 1.14, then install as below:
gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
If you require a particular version of nokogiri e.g -v '1.6.2.1' then install as:
gem install nokogiri -v '1.6.2.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
Nokogiri was installed successfully!
This is the same as #thomas_witt's post but works on Mac OS X Sierra:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
To get the install to work, I had to modify the filepaths in the gem install command to match those on my system. I have different versions of libxml2 and libiconv and a slightly different file structure. The command, with my modifications, is:
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2
--with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib
--with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
--with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include
--with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
For people using MacPorts, make sure you have installed libxml2 via MacPorts. Then type:
bundle config build.nokogiri --use-system-libraries
bundle install
This should do the trick, worked for me without using full paths.
Use brew install libxml2 libxslt if you use Homebrew.
Here is another reference:
system: OS X Yosemite 10.10
rvm: 1.26.10
brew: 0.9.5
ruby: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
I got error while installing nokogiri
error like this:
.rvm/rubies/ruby-2.2.0-p0/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
then probably need:
$ xcode-select --install
or if you got error like
checking for libxml/parser.h... no
I just fix the lib path by:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
for bundle need something like:
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
This works for me
system: OS X Yosemite 10.10
rvm: 1.26.10
ruby: ruby 2.2.1
Just run below two commands
$ xcode-select --install
It will ask you to download say "yes" then it will ask to install the xcode component click install.
Now try to install gem with below command
gem install nokogiri --no-ri --no-rdoc
This works for me with above environment.
I ran into the same issue for Mavrick, and the solution was:
xcode-select --install
However, that is not working as Apple's download page for Command-line-tool does not have that installer available publically now.
So, if you want to have the command-line tools for Mavricks you need to have a paid account. Then only you will be able to install it.
Once you install it you will not face this issue with Nokogiri.
I had this same error on a fresh Mavericks install. After having a lapse of judgement I renamed my Xcode app bundle to Xcode 5.0.1.app.
Apparently the Nokogiri installation script does not quote its paths and so the space in the file name caused all sorts or troubles. It wasn't until I tried brew install libxml2 that the error became obvious.
Lesson learned: spaces in file names are evil.
In my case, I had to actually run /usr/bin/gcc-4.2 after symlinking it. You have to accept the license agreement, otherwise it hangs.
The error message gives a clue here: The compiler failed to generate an executable file. (RuntimeError)
xcode-select --install # not sure if this is required
brew install apple-gcc42
gem install nokogiri
You also might need to brew install and link these:
libxml2 libxslt
brew install libxml2 libxslt
gem install nokogiri -- \
--with-xml2-include=/usr/local/Cellar/libxml2/*/include/libxml2 \
--with-xml2-lib=/usr/local/Cellar/libxml2/*/lib \
--with-xslt-dir=/usr/local/Cellar/libxslt/*
For me the error was that that gcc (4.2.1, installed from Homebrew) was complaining that:
-E, -S, -save-temps and -M options are not allowed with multiple -arch flags
I solved the issue by forcing x86_64 only:
ARCHFLAGS="-arch x86_64" gem install nokogiri
After upgrading to Maverick, I had a similar problem. I use RVM with Ruby 1.9.2-p320, and I tried several solutions given here, but nothing solved the problem.
Then I changed to Ruby 2.1.2, and bundle install installed Nokogiri immediately.
If anyone is having this issue on el capitan, whilst using bundler.
Make sure the xcode command line tools are installed and run this:
bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
I was facing the same issue from past two weeks while trying to run a rails 3 version application.
The issue is that your rvm/rbenv is not using the C compiler.
Use this command for rvm to take compatible C compiler
CC=gcc rvm install-version
So if you are using Ruby 1.9.3, use it this way
CC=gcc rvm install-1.9.3
Use this command every time you are not able to bundle install or anything.
This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7
Hopefully, It will resolve the issue.
I was facing the same issue from past two weeks while trying to run a rails 3 version application.
The issue is that your rvm/rbenv is not using the C compiler.
Use this command for rvm to take compatible C compiler
CC=gcc rvm install-version
So if you are using Ruby 1.9.3, use it this way
CC=gcc rvm install-1.9.3
Use this command every time you are not able to bundle install or anything.
This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7
Hopefully, It will resolve the issue.
And also if you already have the Xcode and then also you are not getting the same errors installing any gem, try this solution.
I added my findings here after I came across this same issue shortly after an Upgrade: http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/
The fix simply is these 2 commands:
xcode-select --install
gem install nokogiri
Hope it helps.
I had this issue as well. Running brew doctor showed that I had an unexpected version of libiconv in /user/local/lib.
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libcharset.1.dylib
/usr/local/lib/libiconv.2.dylib
So I removed them, and rebrewed libxml:
rm /usr/local/lib/libiconv*
andromeda:nokogiri-1.6.0 Jeff$ brew install libxml2 libxslt
...
==> Summary
🍺 /usr/local/Cellar/libxslt/1.1.28: 145 files, 3.3M, built in 36 seconds
Finally, I installed nokogiri:
Jeff$ gem install nokogiri
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.0
1 gem installed
None of these answers worked for my particular case, and since I am a newb I figured my solution might be able to help someone else.
I am using Yosemite and was using Ruby 1.9.3p547. There was a security exposure for p547 so I was trying to update to Ruby 1.9.3p550 or higher. I used RVM, then tried to migrate my gems and many of them didn't go. Then I tried to bundle install but that was failing and I thought maybe it was a conflict between the various paths and dependencies so I removed the older version of Ruby. This broke everything.
I kept getting a message saying that the C compiler was missing, even though I had downloaded XCode and recently updated the CLI tools. I found another website that told me to download a third party GCC, which I did. which made everything worse.
Now I'm getting a message saying I need to fix my profiles and PATHs or it might just be easier to reinstall OSX.
So I did.
Anyway, longer story merely long: the solution that finally worked for me was to get rid of RVM and just use brew to download the Ruby version I wanted then before running bundle install. Install the correct version of Nokogiri FIRST.
brew install ruby193
sudo gem install nokogiri -v '1.6.0'
bundle install
for windows you can also try local installation:
download the appropriate gem based on your environment.
go to the directory where you saved the gem file.
gem install --local nokogiri-1.6.3.1-x86-mingw32.gem
if not worked you may check if you have zlib and mingw or proper c compiler installed.
Every single darn thing on here didn't do it for me (I didn't get into brew reinstalls, oy), but this finally did (found via a bug report on some unrelated project):
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2
Good luck. Yay for #yakshaving!
Check your Commandline tools version. Set up your machine to use the Xcode 5.0.X command line tools, then run:
gem install nokogiri

"rmagick" gem installation issue

I am having issue while trying to install "rmagick" gem on centos. Following is the output I am having. Can anyone please help me identifying what package I am missing? I have installed all mentioned another stack-overflow thread: RMagick install error
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no
Can't install RMagick 2.13.2. Can't find MagickWand.h.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/ruby
Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2/ext/RMagick/gem_make.out
After following suggestions, now I am getting this output:
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/ruby
/usr/local/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /usr/local/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /usr/local/lib/ruby/1.9.1/mkmf.rb:930:in `have_header'
from extconf.rb:194:in `<main>'
Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2/ext/RMagick/gem_make.out
Output Of mkmf.log:
checking for HDRI disabled version of ImageMagick... -------------------- yes
--------------------
"gcc -o conftest -I/usr/local/include/ruby-1.9.1/x86_64-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/ImageMagick-6 -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/ImageMagick-6 conftest.c -L. -L/usr/local/lib -Wl,-R/usr/local/lib -L/usr/lib -lMagickCore-6.Q16 -L/usr/lib -lMagickCore-6.Q16 -Wl,-R -Wl,/usr/local/lib -L/usr/local/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: skipping incompatible /usr/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible /usr/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible /usr/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: cannot find -lMagickCore-6.Q16
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
Output of gem_make.out is same as the terminal output above.
try installing
sudo apt-get install libmagickwand-dev imagemagick
This ImageMagick 7 with RMagick 2.16 on MacOS Sierra Can't find MagickWand.h works for Rmagick 2.16.
brew install imagemagick#6
brew link --force imagemagick#6
gem install rmagick
The error message says:
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
It seems you missing no package at all, you just have to tell pkg-config where to find the MagickCore.pc file to build the extension. If you have installed the package ImageMagick-devel using yum the file should be inside the directory /usr/lib/pkgconfig or /usr/lib64/pkgconfig (depending on your architecture). Check with this command (from now I assume you are on a amd64 machine, if it's not the case replace lib64 with lib):
$ find /usr/lib64/pkgconfig -name MagickCore.pc
If the file is there you just have to install rmagick with this command:
$ PKG_CONFIG_PATH='/usr/lib64/pkgconfig' gem install rmagick
The problem is, as the error puts it,
Package MagickCore was not found in the pkg-config search path
The solution is also suggested there:
add the directory containing MagickCore.pc to the PKG_CONFIG_PATH environment variable
So,
Find MagickCore.pc location:
sudo find / -name MagickCore.pc
If it is not found, probably ImageMagick is not installed on your system — then install it (Google how to do it, as it depends on the OS)
Save it to the ENV var like that (make sure to put the path found in step 1):
PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
Retry installing RMagick
For Mac with Brew, simply..
brew install imagemagick
Then gem install imagemagick will work smoothly.
It doesn't look like you're missing any packages. The error message is important:
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
Several of the answers on this superuser duplicate give good advice.
On debian (unstable) the correct packages needed to resolve this error were libmagickcore-6.q16-dev, imagemagick and libmagickwand-6-headers
I found them by using apt-file search MagickCore.pc and apt-file search MagickWand.h
For windows users who run into this, and are 100% psotive that they have the devkit installed:
When installing, you will be presented this prompt
Choosing 1 is not enough. Just press enter (1 & 3) and that will install the devkit properly.

Resources