When I try to run a ruby on rails project I got an error:
An error occurred while installing nokogiri (1.5.2), and bundle cannot continue.
Make sure that 'gem install nokogiri -v 1.5.2 succeed before building.
I'm working on Ubuntu 10.10
My co-worker uses on Windows/RVM and does not have this problem.
Edit:
gem_make.out
/opt/bitnami/ruby/bin/ruby extconf.rb
extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config.
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
-----
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=/opt/bitnami/ruby/bin/ruby
--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-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-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-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-iconvlib
--without-iconvlib
From the output:
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
Install libiconv.
nokogiri requirements
sudo apt-get install libxslt-dev libxml2-dev
sudo gem install nokogiri
You can visit http://nokogiri.org/tutorials/installing_nokogiri.html
It should not be necessary to install any additonal package. You can use the libraries includes with BitNami (in /opt/bitnami/common). You just need to load the BitNami environment and specify the path to libxml2 files. While testing this I got similar issue but with libxml2, a similar solution can be applied for the iconv error that you are receiving.
$/opt/bitnami/rubyconsole
$sudo gem install nokogiri -- --with-xml2-dir=/opt/bitnami/common --with-xml2-include=/opt/bitnami/common/include/libxml2
Building native extensions. This could take a while...
Successfully installed nokogiri-1.5.2
1 gem installed
Installing ri documentation for nokogiri-1.5.2...
Installing RDoc documentation for nokogiri-1.5.2...
The solution of installing the system packages and used them should also work.
what works for me (Mac OS X):
$ xcode-select --install
Related
I am quite new to development and just trying to set my Windows 10 PC up for Rails development. I found a tutorial that seemed quite clear and achievable here.
I was able to install Ruby 3.1.2 and unzipped it to a permanent folder. I added it to path, and then moved on to build tools. I downloaded MSYS2 from their site and installed, then set up pacman, then RubyInstaller2--installing the MSYS2 and MINGW development toolchain. I was down to installing the C-dependent gems and was able to install sqlite3 using:
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem install sqlite3 --platform ruby
And went on to install nokogiri gem:
ridk execpacman -S mingw-w64-x86_64-libxslt
gem install nokogiri --platform ruby -- --use-system-libraries
This final gem install line is where I have failed. I am very new at most of this and am close to trying to install WSL or a virtual machine, but I thought it was sensible to try and troubleshoot and find the solution.
C:\WINDOWS\system32>gem install nokogiri --platform ruby -- --use-system-libraries
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
current directory: C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/gems/nokogiri-1.13.6/ext/nokogiri
C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/bin/ruby.exe -I C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220511-16300-lhgizk.rb extconf.rb --use-system-libraries
checking for whether -std=c99 is accepted as CFLAGS... yes
checking for whether -Wno-declaration-after-statement is accepted as CFLAGS... yes
checking for whether -g is accepted as CFLAGS... yes
checking for whether -Winline is accepted as CFLAGS... yes
checking for whether -Wmissing-noreturn is accepted as CFLAGS... yes
checking for whether "-Idummypath" is accepted as CPPFLAGS... yes
Building nokogiri using system libraries.
checking for gzdopen() in -lz... yes
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
checking for libxml-2.0 using `pkg_config`... no
Please install either the `pkg-config` utility or the `pkg-config` rubygem.
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
-----
extconf.rb:285:in `ensure_package_configuration'
extconf.rb:648:in `<main>'
xml2 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=C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/bin/$(RUBY_BASE_NAME)
--help
--clean
--prevent-strip
--enable-system-libraries
--disable-system-libraries
--use-system-libraries
--enable-system-libraries
--disable-system-libraries
--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-z-dir
--without-z-dir
--with-z-include
--without-z-include=${z-dir}/include
--with-z-lib
--without-z-lib=${z-dir}/lib
--with-zlib
--without-zlib
--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-xml2lib
--without-xml2lib
--with-libxml2-dir
--without-libxml2-dir
--with-libxml2-include
--without-libxml2-include=${libxml2-dir}/include
--with-libxml2-lib
--without-libxml2-lib=${libxml2-dir}/lib
--with-libxml2lib
--without-libxml2lib
--with-libxml-2.0-dir
--without-libxml-2.0-dir
--with-libxml-2.0-include
--without-libxml-2.0-include=${libxml-2.0-dir}/include
--with-libxml-2.0-lib
--without-libxml-2.0-lib=${libxml-2.0-dir}/lib
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--with-xml2lib
--without-xml2lib
--with-libxml2lib
--without-libxml2lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/nokogiri-1.13.6/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/gems/nokogiri-1.13.6 for inspection.
Results logged to C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/nokogiri-1.13.6/gem_make.out
C:\WINDOWS\system32>
So, when I read the bit about "please install the pkg-config rubygem, I looked up how to do it and tried to install in MSYS2, which it appeared to do.
windows is not really the best option with rails there will be a lot of issues and everything gets more complicated see this Limitations in running Ruby/Rails on windows
Linux is highly recommend
you can use dual-booting or WSL either is fine
I am getting an error and bundle install fails:
An error occurred while installing nokogiri (1.9.1), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.9.1' --source 'https://rubygems.org/' succeeds before bundling.
I have tried many commands from stack overflow but no luck yet.
After reading some posts about the issue I added the following environment variables but the bundle install still fails.
export PATH="/usr/local/opt/libxslt/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/libxslt/lib"
export CPPFLAGS="-I/usr/local/opt/libxslt/include"
sudo gem install nokogiri -v "1.9.1" -- --use-system-libraries
Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/wiii/.rbenv/versions/2.1.5/bin/ruby extconf.rb --use-system-libraries
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 system libraries.
checking for xmlParseDoc() in libxml/parser.h... yes
checking for xsltParseStylesheetDoc() in libxslt/xslt.h... no
checking for xsltParseStylesheetDoc() in -lxslt... no
checking for xsltParseStylesheetDoc() in -llibxslt... no
-----
libxslt 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/wiii/.rbenv/versions/2.1.5/bin/ruby
--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
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-exslt-dir
--without-exslt-dir
--with-exslt-include
--without-exslt-include=${exslt-dir}/include
--with-exslt-lib
--without-exslt-lib=${exslt-dir}/lib
--with-libexslt-config
--without-libexslt-config
--with-xsltlib
--without-xsltlib
--with-libxsltlib
--without-libxsltlib
extconf failed, exit code 1
Debugging info are attached below:
$ which ruby
/Users/wiii/.rbenv/shims/ruby
$ which bundle
/Users/wiii/.rbenv/shims/bundle
$ which gem
/Users/wiii/.rbenv/shims/gem
$ ruby --version
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin19.0]
$ bundle --version
Bundler version 1.17.3
$ gem --version
2.2.2
Homebrew
% brew list
ansible kind libxslt openssl#1.0 ruby-build
autoconf kubectx libyaml openssl#1.1 sqlite
gdbm kubernetes-cli mpdecimal pkg-config tcl-tk
go libgcrypt mysql#5.7 protobuf tomcat#8
htop libgpg-error ncurses python#3.9 xz
icu4c libiconv node rbenv
k9s libxml2 openjdk readline
intellij-idea
Could anyone share some thoughts on what might be causing the issues here?
Nokogiri is an open source software library to parse HTML and XML in Ruby. It depends on libxml2 and libxslt to provide its functionality. without it Rails is non-functional.
it seems as if your macOS is missing some essential libraries required for nokogiri to run on your computer.
you can go ahead and first uninstall nokogiri and any other interfering library that you might have installed during your endeavor to solve this issue
run brew uninstall nokogiri
upon uninstalling, you can run brew install libxml2 libxslt to install the most essential libraries using brew
after that, run gem install nokogiri --platform=ruby -- --use-system-libraries to successfully install nokogiri
I'm running Mac OSX "Yosemite", and I've been trying to install Nokogiri 1.6.1, but I keep running into the error below.
This is the error I ran into when I was trying to install Nokogiri 1.6.1:
sh-3.2# gem install nokogiri -v 1.6.1
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150819-49747-fafnk9.rb extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxslt/1.1.26)...
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... no
-----
libxml2 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--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-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-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-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-libiconv-config
--without-libiconv-config
--with-iconvlib
--without-iconvlib
--with-xml2lib
--without-xml2lib
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.1/gem_make.out
I tried everything on http://www.nokogiri.org/tutorials/installing_nokogiri.html, but I have been unsuccessful. I tried to install libxml2 to install Nokogiri 1.6.1, but my terminal says:
Cowardly refusing to `sudo brew install`
Sometimes installing Nokogiri is tricky as it has several dependencies, which is what happened in your case too.
"Installing Nokogiri" is a step-by-step tutorial on how to install Nokogiri on your Mac OSX system.
You need to install Package first
xcode-select --install
then
gem install nokogiri
I've been experiencing a lot of problems with this gem, so I read that I had to use de 1.5.0-beta.
Since I'm using windows, I downloaded DevKit. But when I ran:
gem install nokogiri --pre -- --with-xml2-lib --with-xslt-lib
I get:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
C:/Ruby187/bin/ruby.exe extconf.rb --with-xml2-lib --with-xslt-lib --pla
taform=ruby
*** 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=C:/Ruby187/bin/ruby
--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-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib=${xml2-dir}/lib
C:/Ruby187/lib/ruby/1.8/mkmf.rb:1177:in `dir_config': private method `split' cal
led for true:TrueClass (NoMethodError)
from extconf.rb:87
Gem files will remain installed in C:/Ruby187/lib/ruby/gems/1.8/gems/nokogiri-1.
5.0.beta.4 for inspection.
Results logged to C:/Ruby187/lib/ruby/gems/1.8/gems/nokogiri-1.5.0.beta.4/ext/no
kogiri/gem_make.out
What can I do?
With a command like
gem install nokogiri --pre -- --with-xml2-lib --with-xslt-lib
it looks like you're trying to install the very latest version of nokogiri. Try specifying a precise version with --version.
Also note the following requirements for nokogiri 1.6+
ruby 1.9.3 or higher
in Nokogiri 1.6.0 and later, libxml2 and libxslt are no longer requirements
So, if you do want to use ruby 1.8.7 (which is EOL, btw) then, yes, you do need to specify nokogiri < 1.6. However, if you can use a modern, living ruby, then you might dodge the lib dependencies.
I was trying to install webrat on my Mac, but I've got the error, that the iconv.h is missing. Here is the log:
Building native extensions. This could take a while...
ERROR: Error installing webrat:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for iconv.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/include,/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/include/libxml2,/usr/include,/usr/include/libxml2... no
iconv is missing. try 'port install iconv' or 'yum install iconv'
*** 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/1.8/usr/bin/ruby
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-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-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/nokogiri-1.4.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/nokogiri-1.4.1/ext/nokogiri/gem_make.out
The weird thing is, that the iconv.h is already in the /opt/local/include/ directory.
Can anyone recommend a solution?
thx,
tux
Ok, I solved it on my own.
After a couple of days on research and trying I figured out, that my installation of g++ and gcc was broken. I've installed an update of g++ through macports, and in the .profile file of my current user there was a value in the PATH var from macports. I removed it, and now it works.
The PATH var should look like this:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
More help on Nokogiri website, using macports or homebrew for Mac OS X install:
http://nokogiri.org/tutorials/installing_nokogiri.html
For iconv related problems, please refer to this issue on github:
https://github.com/tenderlove/nokogiri/issues/381