Nokogiri error on installation due to missing nati

2019-06-24 03:37发布

I have been trying to install Ruby on Rails based on these instructions. However, I am getting the following error upon running gem install rails -v 4.2.4:

Fetching: rack-1.6.4.gem (100%)
Successfully installed rack-1.6.4
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /home/falak/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150909-22683-172bl7d.rb extconf.rb
checking if the C compiler accepts ... *** 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=/home/falak/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME)
    --help
    --clean
/home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
    from extconf.rb:80:in `nokogiri_try_compile'
    from extconf.rb:87:in `block in add_cflags'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
    from extconf.rb:86:in `add_cflags'
    from extconf.rb:337:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /home/falak/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /home/falak/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/nokogiri-1.6.6.2/gem_make.out

I tried installing nokogiri using system libraries by running gem install nokogiri -v 1.6.2.1 -- --use-system-libraries, but I got the following error:

Building native extensions with: '--use-system-libraries'
This could take a while...
Building nokogiri using system libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /home/falak/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150909-23169-twqmu6.rb extconf.rb --use-system-libraries
Building nokogiri using system libraries.
*** 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=/home/falak/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME)
    --help
    --clean
    --use-system-libraries
    --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-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
/home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:541:in `try_link0'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:637:in `try_ldflags'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:1780:in `pkg_config'
    from extconf.rb:338:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /home/falak/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /home/falak/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/nokogiri-1.6.2.1/gem_make.out

6条回答
戒情不戒烟
2楼-- · 2019-06-24 03:58

Try installing the libgmp-dev library

apt-get install libgmp-dev
查看更多
我命由我不由天
3楼-- · 2019-06-24 03:59

For OS X users: remember update the Xcode command line developer tools, this is the problem for the 99% OS X users. xcode-select --install

查看更多
Melony?
4楼-- · 2019-06-24 04:16

Using RVM to install rails in ruby 2.2.3 has been a major problem among other users as well. For now, you can still get rails 4.2.4 in ruby 2.2.2. Try:

    rvm install 2.2.2
    rvm --default use 2.2.2
    gem install rails

this should still work. RVM for some reason does not install the right headers in 2.2.3 for you to build the gems.

查看更多
混吃等死
5楼-- · 2019-06-24 04:16

You can try this amazing solution for this

The solution is:

sudo apt-get install ruby-dev

Or, if that doesn't work, depending on your ruby version, run something like:

sudo apt-get install ruby1.9.1-dev

Should fix your problem.

Still not working? Try the following after installing ruby-dev:

sudo apt-get install make
查看更多
我只想做你的唯一
6楼-- · 2019-06-24 04:18

As the error says check in the mkmf.log file. There you'll find the missing header files.

In my case I was missing zlib.h. The error was:

The #include file "zlib.h" is not found

So to fix it:

sudo apt-get install zlib1g-dev

To find required dev packages, one can use apt-file

$ apt-file search zlib.h
zlib1g-dev: /usr/include/zlib.h
查看更多
神经病院院长
7楼-- · 2019-06-24 04:20

This solution is for nokogiri error:

sudo apt-get install ruby-dev
查看更多
登录 后发表回答