Alvin Jones
Alvin Jones

Reputation: 251

Error - "gem install rails" - libxml2 is missing

I've been working through the Rails install instructions (http://railsapps.github.io/installrubyonrails-mac.html) and everything was okay up until I got to gem install rails part under New Rails Application. When I ran that I got libxml2 is missing. Here's the log: http://codecascade.com/sIjhQ/raw

I had similar issues install nokogiri, and the only way I was able to get it resolved was with

gem install nokogiri -- --use-system-libraries

I'm on OS X 10.10.2. I also have RubyMine installed if that's potentially relevant.

Upvotes: 8

Views: 8842

Answers (8)

C.L
C.L

Reputation: 1

I had the same problem when I try:

gem install libxml-ruby -v '3.0.0

Run the following solved the issue on Mac for me:

gem update --system

xcode-select --install

gem install nokogiri

See installing nokogiri for more details

Upvotes: 0

Sean
Sean

Reputation: 2529

This worked for me (based on this Github thread):

gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

As a note, my issue was:

...
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.

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=/Users/seanshadmand/.rvm/rubies/ruby-2.1.1/bin/ruby
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build
    --with-xml2lib
    --without-xml2lib
    --with-libxml2lib
    --without-libxml2lib

To see why this extension failed to ...

extconf failed, exit code 1

Upvotes: 1

ninja79
ninja79

Reputation: 11

I had the same issue, on Debian it seemed only a problem of missing 'dev' libraries, probably needed to compile sources during installation (I'm guessing). I solved it by installing (via apt-get or aptitude) the following packages:

  • Libxml2-dev
  • Libxslt1-dev

Upvotes: 1

Legendary
Legendary

Reputation: 2242

You don't have the required library, and it is so easy to google solution:

 brew install libxml2

Upvotes: 6

Shunzhe
Shunzhe

Reputation: 1

It worked for me as Simar has mentioned.

sudo gem install rails -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/

And if you were having troubles install it on Mac please check out here. https://gorails.com/setup/osx/10.11-el-capitan

Also if you could not find /usr/local/Cellar/libxml2/ existing, you may need to homebrew it.

brew install libxml2

If you are installing it on a newly installed OS X EL CAPITAN as I do, you probably find homebrew telling you that libxml2 is installed already and brew will not replace the existing libxml2 with it's newly installed one which is at /usr/local/Cellar/libxml2/, which is the one we really should link the libraries to. Since the system default libxml2 would not link successfully.

Upvotes: 0

przemo_li
przemo_li

Reputation: 4053

For some reason nokogiri build process for libxml2 will misplace build version.

Instead of lib/ it will to go lib64/. Nokogiri will then look for it in the wrong directory.

More info here: https://github.com/sparklemotion/nokogiri/issues/1334

Upvotes: 0

Simar
Simar

Reputation: 2505

Try using this:

sudo gem install rails -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/

Upvotes: 4

NotYanka
NotYanka

Reputation: 547

I just had the same problem and was able to solve it as follows:

Installing Nokogiri separately worked only when using the system libraries:

gem install nokogiri -- --use-system-libraries

...but was still failing when executing bundle install. So just configure bundler to also build Nokogiri using the system libraries:

bundle config build.nokogiri --use-system-libraries

Upvotes: 7

Related Questions