Libxml2 missing mac os x 10.10 - ruby

Running 'compile' for libxslt 1.1.28... OK
Running 'install' for libxslt 1.1.28... OK
Activating libxslt 1.1.28 (from /Users/Kartik/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/nokogiri-1.6.4.1/ports/x86_64-apple-darwin14.0.0/libxslt/1.1.28)...
checking for main() in -llzma... yes
checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
libxml2 is missing. Please locate mkmf.log to investigate how it is failing.
*** 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.

i fiddled around with this for quite a while and the following worked for me..
1) install libxml2 with homebrew
brew install libxml2
2) install the gem via
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri:1.6.4.1 -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/

For any who are still getting "libxml2 version 2.6.21 or later is required!" message, removing --use-system-libraries from hlv's step 2 above, worked for me.
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri:1.6.4.1 -- --with-xml=/usr/local/Cellar/libxml2/2.9.2/

I finally ended up with this version independent line:
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -n /usr/local/bin -- --with-xml=/usr/local/Cellar/libxml2/

This worked for me (assuming Xcode is installed):
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.‌platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-libraries
Inspired by https://stackoverflow.com/a/28767045/1884907 (credits to lx00st)

(For MacOX 10.12.x) Perhaps you want to brew install libxml2 and also try linking into /usr/local/ first: brew link --force libxml2, then try that gem install nokogiri -- --use-system-libraries.

Using ports:
gem install nokogiri -- --use-system-libraries --with-xml=/opt/local/lib/libxml2.a

My solution, using ports:
sudo ARCHFLAGS='-arch x86_64' gem install nokogiri -- --use-system-libraries
By default, it will compile for x86_64 and i386, architecture for i386 should disabled, because the dependencies libraries in port only provide x86_64 version by default.

This is a bit of a rehash of all the other answers, but this worked for me:
gem install nokogiri -v '1.6.6.2' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.16 --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 --use-system-libraries

Related

Nokogiri gem fails to install in OS X Mavericks

Install fails showing:
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
checking for libiconv_open() in -liconv... no
libiconv is missing.
However, looking at nokogiri's mkmf.log, the following errors are shown:
ld: warning: ignoring file /usr/local/Cellar/libxslt/1.1.28/lib/libxslt.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libxslt/1.1.28/lib/libxslt.dylib
ld: warning: ignoring file /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.dylib
ld: warning: ignoring file /usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib
I have xcode and it's command tools installed.
My ~/.bash_profile has 64bit compiling forced by: export ARCHFLAGS="-arch x86_64"
I have libxml2, libxslt, and libiconv installed via Homebrew, and each is linked.
I've tried installing all of these without the ARCHFLAG in .bash_profile.
I've also brew install apple-gcc42 and linked, as per how tos I've found.
I've tried installing nokogiri by passing paths to libxml2, libxslt, and libiconv in /usr/local/Cellar/, but the install still fails, with same errors as above.
I've wasted at least a day on this - just trying to get one Ruby gem installed. I'd really like to get back to actually developing.
Can anyone please help?
Setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before actually installing the gem did the trick for me.
Summarising:
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv if needed:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
Check if HomeBrew is installed correctly with the appropriate XCode command line tools.
brew doctor
You can also check via XCode > Preferences
With valid command line tools installed, I was able to resolve the nokogiri error encountered after the OSX Maverick upgrade.
Also found that some of the 'brew' packages were outdated after the OS X Mountain Lion to Maverick upgrade. (e.g. qt, postgresql)
Here's what worked for me:
If you haven't already done so, install the XCode developer tools: $ xcode-select --install
Use homebrew to install (or reinstall) libxml2, libxslt and libiconv: $ brew install libxml2 libxslt libiconv
Install nokogiri: gem install nokogiri -- --with-iconv-dir=/usr/local/opt/libiconv
I found the solution I needed in an unmerged pull request to update the Nokogiri tutorials. I recommend that if someone else encounters this issue and has exhausted the solutions here, check that pull request list to see if someone has submitted an update to the instructions on the Nokogiri tutorials page.
From github page
First, you should:
xcode-select --install
and then re-install nokogiri.
That worked for me while another suggestion didn't. Hope this helps someone else.

Failed to build gem native extension

I want to install in my Fedora 12 based planet lab nodes one OMF RC:
It requres ruby 1.9.3. So, I installed git, then ruby-devel then rvm. With rvm i installed:
rvm install 1.9.3
After all this when i want to install:
gem install omf_rc --pre --no-ri --no-rdoc
It gives me the following error:
Building native extensions. This could take a while...
ERROR: Error installing omf_rc:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p194/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
Please let me know how to solve this. Thanks
seems you need to install libxml, try:
sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
Also it needs the following installation:
sudo yum install -y git make gcc-c++
and
sudo yum groupinstall development-tools development-libs

How to install Nokogiri Ruby gem with mkmf.log saying libiconv not found?

I'm installing the Ruby Nokogiri gem and finding the error below.
How to diagnose this and solve it?
# gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
...
/opt/ruby/1.9.3-p194/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.
...
/opt/ruby/1.9.3-p194/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 /opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
...
To diagnose and solve, here's what worked for me.
To find out what failed, go to your ruby gems directory.
For example:
$ cd <MY RUBY DIRECTORY>/lib/ruby/gems/2.0.0/gems
If you don't know your gem directory, try this:
$ echo $GEM_HOME
/opt/gems/2.0.0
$ cd /opt/gems/2.0.0/gems
What version of nokogiri am I installing?
$ ls -ladg nokogiri-*
nokogiri-1.5.5
Go to the installer directory:
$ cd nokogiri-1.5.5/ext/nokogiri
Try installing manually:
$ ruby extconf.rb
Result:
checking for libxml/parser.h... *** extconf.rb failed ***
...
I'm using Ubuntu so I search for any similar packages:
$ aptitude search libxml
Results:
p libxml2 - GNOME XML library
p libxml2-dev - Development files for the GNOME XML library
...
I believe that libxml2 will work fine.
$ apt-get install libxml2
Ruby native gems often need the *-dev packages for headers so install them:
$ apt-get install libxml2-dev
Now do I have the parser file?
$ find / | grep libxml/parser.h
Yes, the result shows the parser:
/usr/include/libxml2/libxml/parser.h
Now try installing again, this time providing the libxml2 path:
$ gem install nokogiri -- --with-xml2-dir=/usr/include/libxml2
It still fails, so read the mkmf error log:
$ more mkmf.log
The error log shows what failed and has these lines that look promising:
package configuration for libxslt is not found
Is there a package for it?
$ aptitude search libxslt
Results:
v libxslt-dev
i libxslt-ruby
...
Install the dev package:
$ apt-get install libxslt-dev
Now try installing again, and also put xslt on the path:
$ gem install nokogiri -- \
--with-xml2-dir=/usr/include/libxml2 \
--with-xslt-dir=/usr/include/libxslt
Success!
Installing Nokogiri Website
'Installing Nokogiri' is a website dedicated to installing Nokogiri on the major platforms - Here is an excerpt about Installing Nokogiri on Ubuntu:
Because Nokogiri needs to be compiled and dynamically linked against
both libxml2 and libxslt, it has gained a reputation for being
complicated to install.
As of Nokogiri 1.6, libxml2 and libxslt source code is bundled with
Nokogiri, and compiled at gem-install-time. The instructions in this
document should work for all versions 1.6.4 and later.
Ubuntu / Debian
Installation should Just Work™ on Ubuntu and Debian using Nokogiri’s
vendored libxml2 and libxslt:
gem install nokogiri
[...]
Using Your System Libraries
If, instead of Nokogiri’s vendored libraries, you’d like to use your
system’s libxml2, libxslt and related libraries, please first
understand that you may be asking Nokogiri to work with an unsupported
version of libxml2.
sudo apt-get install pkg-config
gem install nokogiri -- --use-system-libraries
FYI - I am using Nokogiri 1.6.6.2 and it didn't 'just work'. I got it going with the --use-system-libraries.
Mac OS X
The website's advice also covers OS X - this worked for me:
gem update --system
xcode-select --install
gem install nokogiri
Conclusion
If you have a Nokogiri problem on any platform you should check out the website.
On CentOS here is what I needed to do:
gem update --system
yum install libxml2-devel libxslt-devel ruby-devel
gem install nokogiri -- --use-system-libraries
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.
You are probably missing zlib headers which are required for -lz flag in order to compile the sources correctly. Install on Linux by:
sudo apt-get install libz-dev
For missing libiconv, try installing libiconv-hook-dev package which has header files of libiconv-hook, e.g.
sudo apt-get install libiconv-hook1 libiconv-hook-dev
On OS X, try installing development tools via: xcode-select --install.
If there is still problem, check mkmf.log file for more specific details about your error.
On Ubuntu, try the following dependency fix combo:
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
The 'could not create Makefile' error you're seeing could also be because you haven't agreed to the Xcode license (you have to agree to it after each time you update Xcode). Running sudo xcodebuild -license accept should eliminate this error for you and allow you to then run gem install nokogiri successfully.

ERROR: Error installing ffi: ERROR: Failed to build gem native extension

Got the DevKit installed and re-ran the ffi install….got this as an output:
C:\Documents and Settings\******>gem install ffi
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
C:/Ruby192/bin/ruby.exe extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include... no
checking for rb_thread_blocking_region()... yes
checking for ruby_thread_has_gvl_p()... yes
checking for ruby_native_thread_p()... yes
checking for rb_thread_call_with_gvl()... yes
creating extconf.h
creating Makefile
make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_ffi_c'" > ffi_c-i386-mingw32.def
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1
.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DRUBY_EXTCONF_H=\"extcon
f.h\" -O3 -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -
Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-declaration-a
fter-statement -o AbstractMemory.o -c AbstractMemory.c
In file included from AbstractMemory.c:28:0:
compat.h:65:20: warning: extra tokens at end of #ifndef directive
compat.h:69:24: warning: extra tokens at end of #ifndef directive
In file included from AbstractMemory.h:29:0,
from AbstractMemory.c:29:
Types.h:68:17: fatal error: ffi.h: No such file or directory
compilation terminated.
make: *** [AbstractMemory.o] Error 1
Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.1
0 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.10/ext/ffi_c/gem_m
ake.out
_________________________________________________________________________________
Not sure how to deal with this issue. Kindly help.
The gem install ffi fails due to the gem trying to build a bundled copy of libffi, which does not work due to assumptions that /usr/bin/env exists and too old libffi copy.
However, you can build the ffi gem against the system libffi - install the packages:
apt install clang make ruby-dev libffi-dev
After that the ffi gem should build:
gem install ffi
Version 1.0.10 has issues compiling on windows.
You can use the 1.0.9
gem install ffi --version='1.0.9'
sudo apt-get install libffi-dev
This worked for me
For me the fix was running in this order. I'm not sure what all was relevant, but it worked:
gem install ffi --version '1.0.9'
The above failed, but then I could successfully run:
gem install bundler
...and subsequently:
gem install ffi
...which got the latest version (1.6.0 at the time of writing this) and installed it successfully.
Note that installing version 1.0.9 isn't going to be enough if your bundler keeps trying to go out and grab the latest version. In your gemfile you'll also want to put:
gem 'ffi', '1.0.9'
This should satisfy the dependency for whatever gem is asking for it and let you get up and running.
when the above steps are followed, it might results the following message.
$ bundle install
Fetching source index for https://rubygems.org/
You have requested:
ffi = 1.0.9
The bundle currently has ffi locked at 1.0.11.
Try running `bundle update ffi`
In that case, you can run the 'bundle update ffi' command and the error will be solved.
Installing the 'osx-gcc-installer' worked for me: (osx 10.8)
https://github.com/kennethreitz/osx-gcc-installer/downloads
Helped me:
sudo apt install build-essential
Debian 9
Ruby 2.3.3
you need this,
apt-get install ruby2.2-dev
Copied from another post:
As stated in Issue with installing ImageMagick and rmagick on Mountain Lion, ffi appears to be configured to look for 'gcc-4.2', so once I updated my Apple command line tools (which I may or may not have needed to do), I created a symbolic link to make the ffi install configuration happy:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
For me, this usually works
gem install ffi -- --disable-system-libffi
On MacOS (Catalina), running brew install libtool first solved the problem for me.
This worked for me
gem install ffi -- --disable-system-libffi
on Ubuntu 20.04 (WSL)
Put DevKit in front of your PATH, and install again from Windows command prompt.
I got the same problem. In my case, I have not install the DevKit, which can be found: http://rubyinstaller.org/downloads/. After installing DevKit, just follow the instruction https://github.com/oneclick/rubyinstaller/wiki/development-kit and finally it's up and running.
I had to install automake to get it working. Worked on both mac OSX as well as Ubuntu (CI machine).
Run this: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then: brew install cocoapods

sqlite3-ruby install error on Ubuntu

I have the following error during sqlite3-ruby install:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite3-devel'
*** 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/bin/ruby1.8
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/lib
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.3.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.3.1/ext/sqlite3/gem_make.out
sqlite3.h is located in /usr/include/
sudo gem install sqlite3-ruby --without-sqlite3-include=/usr/include
doesn't work
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --without-sqlite3-include=/usr/include
Ubuntu 10.04
You need the SQLite3 development headers for the gem’s native extension to compile against. You can install them by running (possibly with sudo):
apt-get install libsqlite3-dev
You just need a -- in there.
sudo gem install sqlite3-ruby -- --with-sqlite3-include=/usr/include
That specifies that the option is not to gem directly, but the specific gem.
In my case I have no basic compilers installed, so
sudo apt-get install build-essential
solved my problem, but for most the people I think https://stackoverflow.com/a/3649005/417267 is the solution.
This is what I did:
wget http://www.sqlite.org/sqlite-amalgamation-3.7.2.tar.gz
tar xzf sqlite-amalgamation-3.7.2.tar.gz
cd sqlite-3.7.2/
./configure
make
make install
gem install rails sqlite3-ruby
from : http://cuasan.wordpress.com/2010/10/13/rails-3-on-debian-with-sqlite-3/
If you run in ubuntu,and using RVM for ruby on rails,please add FIRST:
sudo apt-get install libxslt-dev libxml2-dev
OR You can check with these commands:
This command will prepare for you two packages : sqllite3 and libsqlite3-dev
sudo apt-get install sqlite3
libsqlite3-dev
-Now,install sqlite gem
[sudo] gem install sqlite3-ruby
-using Ubuntu doesn't need sudo.
Goodluck! Note: i'm using Ubuntu 10.10 and it's working.
This was simply enough to make it work
sudo apt-get install libsqlite3-dev
Thanks to marshluca
Tried ALL of other solutions, none helped.
It turned out that you also need dev package for ruby itself. For me, it helped
sudo apt-get install ruby-full
It has a lot of nasty dependencies though (like emacs, wtf?), just
sudo apt-get install ruby1.8-dev
should be fine. After it's installed (and you have the sqlite and sqlite-dev packages installed)
sudo gem install sqlite3-ruby
works like a charm.
From sqlite3-ruby gem can't find sqlite3.h on ubuntu:
You also need to install gcc itself, so in total it would be:
sudo apt-get install gcc libsqlite3-dev ruby1.8-dev
sudo gem install sqlite3
Apparently you get a wrong error pointing to a missing sqlite3.h when the actual problem is missing gcc itself.
Here's a better answer from HEROKU - cannot run git push heroku master
Since you can't use sqlite3 on heroku add this to your Gemfile:
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
The solution is to add -- to separate configure parameters from gem parameters.
instead of
sudo gem install sqlite3-ruby --without-sqlite3-include=/usr/include
try this, all on one line, make sure to include -- after the last gem parameter and before configure parameters:
sudo gem install sqlite3 --
--with-sqlite3-lib=/somewhere/local/lib
--with-sqlite3-include=/somewhere/local/include
This should get you around this error:
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --without-sqlite3-include=/usr/include
Had this same problem and the following worked for me:
compile sqlite3 as static library, install somewhere in your home directory and then provide that option for the gem install process.
Go to the download page and grab the source. Most recent version at this time is http://www.sqlite.org/sqlite-autoconf-3070400.tar.gz
tar -xf on the file or do whatever you normally do to uncompress; enter directory
./configure --disable-shared --enable-static --prefix=/some/path/in/my/home
compile, install, and when you're installing the gem...
gem install sqlite3-ruby -- --with-sqlite3-dir=/some/path/in/my/home
None of the above mentioned solution worked for me, even after installing ruby2.5-dev and libsqlite3-dev. Then tried using PostgreSql instead of sqlite. That worked fine. To use PostgreSql instead of sqlite use this command when creating rails project.
rails [_VERSION_] new project_name -d postgresql
If you want to use MySql then use mysql instead of postgresql.
rails [_VERSION_] new project_name -d mysql
Else you can try without sqlite.
bundle install --without sqlite
Not --without-sqlite3-include=/usr/include, but --with-sqlite3-include=/usr/include.
This is the exact same problem I had a few weeks ago. I found out I needed to download the most recent headers/libraries from the SQLite Download Page. Try it out, hope this helps!
For me the problem was solved by getting mkmf, which is in ruby1.8-dev.
sudo apt-get install ruby1.8-dev
Thanks to mentalized for that one.
I agree with Danya Vershinin & EnotionZ.
If can't use apt-get:
compile & install sqlite3 from sources by specifying your own "prefix" path.
More information can be found in the README.
Then passed this path to the sqlite3-ruby installer (don't forget the "--").
You have broken version of RVM. Ubuntu does something to RVM that produces lots of errors, the only safe way of fixing for now is to: sudo apt-get --purge remove ruby-rvm sudo rm -rf /usr/share/ruby … , if it does not help then restart your computer. install RVM: \curl -L https://get.rvm.io | bash -s stable --ruby --autolibs=enable --auto-dotfiles If you find you need some hand-holding, take a look at Installing Ruby on Ubuntu 12.04, which gives a bit more explanat
Forget everything and do this,
run
yum install ruby-devel sqlite sqlite-devel ruby-rdoc
yum install make gcc
gem install sqlite3-ruby
bundle install
That's for rhel, run same for ubuntu.
I just downgraded to sqlite3-ruby '1.2.2'

Resources