终端输入
sudo gem install rails -V
报错
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/test/xslt/test_custom_functions.rb
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/test/xslt/test_exception_handling.rb
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/test_all
Building native extensions. This could take a while...
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/ext/builder.rb:51: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... no
-----
libiconv 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/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
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
Building has failed. See above output for more information on the failure.
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2 for inspection.
直接安装Nokogir
按照官网步骤
#sudo gem install nokogiri
同样的错误,失败
#sudo gem install nokogiri -- --use-system-libraries
同样的错误,失败
#sudo gem install nokogiri -- \
--use-system-libraries \
--with-xml2-lib=/usr/lib \
--with-xml2-include=/usr/include/libxml2 \
--with-xslt-lib=/usr/lib \
--with-xslt-include=/usr/include/libxslt
成功
结论,没有找到libxml2和libxslt的头文件和库的路径。