An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.

系统为mac os 10.11,command tool什么的都安装了

在执行bundle install时出现下面错误:

An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.

  Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.

往前翻了下,错误详细为:

Installing nokogiri 1.6.2.1 with native extensions
Building nokogiri using packaged libraries.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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
    --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


Gem files will remain installed in /Users/sophia/ashelf/vendor/bundle/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Users/sophia/ashelf/vendor/bundle/gems/nokogiri-1.6.2.1/ext/nokogiri/gem_make.out

里面有一句:“libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.”

试了一下这个方法:

 brew install libiconv

brew link libiconv

然后看到输出的链接地址为“/usr/local/Cellar/libiconv/1.14/

执行命令:

gem install nokogiri  -v '1.6.2.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/

再bundle install还是不行,最后找到一个方法:

bundle config build.nokogiri -v '1.6.2.1' \

      --with-iconv-lib=/usr/local/lib \

      --with-iconv-include=/usr/local/include

然后再bundle install 就可以了。

 

上面的命令每次执行都没有加 -v '1.6.2.1' ,所以一直装的1.6.7.2,导致bundle install总失败,好二啊/(ㄒoㄒ)/~~

posted @ 2016-02-03 00:21  Sophiawow  Views(1662)  Comments(0Edit  收藏