Windows 10 + Ruby 3.1.2 -- Cannot install nokogiri - ruby-on-rails

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

Related

nokogiri 1.9.1 install failed on MacOS Catalina

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

Error when installing rails, failed to build gem native extension

I'm following this Go Rails tutorial and I'm running into trouble when I reach the step to install rails. I'm calling
sudo gem install rails -v 5.0.1
in the terminal and getting this error:
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: /usr/local/lib/ruby/gems/2.4.0/gems/nokogiri-1.7.0.1/ext/nokogiri
/usr/local/opt/ruby/bin/ruby -r ./siteconf20170302-50105-1af2foa.rb extconf.rb
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.
Using mini_portile version 2.1.0
checking for iconv.h... yes
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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
--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/Cellar/ruby/2.4.0/bin/$(RUBY_BASE_NAME)
--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
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0/nokogiri-1.7.0.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /usr/local/lib/ruby/gems/2.4.0/gems/nokogiri-1.7.0.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0/nokogiri-1.7.0.1/gem_make.out
I'm not really sure what to make of this. I've tried reinstalling uninstalling and reinstalling zlib but it didn't seem to change anything. I'm on OS X Sierra version 10.12.3 by the way.
Solved by this thread using
sudo gem install rails -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/

Ubuntu 14.04 Rails missing file

when installing Rails, everything was good but then, i write:
rails -v
and the output:
/home/toshiba/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- rails/cli (LoadError)
from /home/toshiba/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/bin/rails:7:in `<main>'
everyone know how to do it?
I used this tutorial: http://installfest.railsbridge.org/
and yes, i run:
gem install rails
I noticed that when i run install rails this thing is pop up
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/home/toshiba/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150816-3818-sm5w21.rb extconf.rb
checking if the C compiler accepts -ggdb3 -O0 -std=c99 -Wall -Werror... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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/toshiba/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--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
extconf failed, exit code 1
Gem files will remain installed in /home/toshiba/.rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /home/toshiba/.rvm/gems/ruby-2.2.1/extensions/x86_64-linux/2.2.0/nokogiri-1.6.6.2/gem_make.out
It seems bad
I've fixed this problem by
sudo apt-get install zlib1g-dev
This pops up in your install process:
zlib is missing; necessary for building libxml2
I guess you need to sudo apt-get install libxml2.
Edit I got downvoted and probably the answer about installing zlib is (more?) correct. I wonder if installing libxml2 (or libxml2-dev) would have helped as well, there was unfortunately no comment about output of that experiment.

Trouble Installing Nokogiri on Mac OS X Yosemite v.10.10.1 because of libxml2 while upgrading to Rails 4.2.0

I'm trying to install Rails 4.2.0 on my computer, but I am having issues installing Nokogiri. I followed the steps in the first answer for "bundle install stopped at Nokogiri", but when I run brew install nokogiri, I get the following:
Activating libxslt 1.1.28 (from /Users/dseibert/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2/ports/x86_64-apple-darwin14.0.0/libxslt/1.1.28)...
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
--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/dseibert/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
--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
extconf failed, exit code 1
Gem files will remain installed in /Users/dseibert/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/dseibert/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0/nokogiri-1.6.6.2/gem_make.out
I cant find the mkmf file to locate the details of my libxml2 file, and I don't see either the libxml2 file or the Nokogiri folder within my Ruby source folder.
And when I run brew install libxml2, I get Warning: libxml2-2.9.2 already installed.
Following the comment, I got the response: Successfully installed nokogiri-1.6.6.2. But when I ran sudo gem install rails, I got back the above error again.
Try this
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/
This works on OSX 10.11 El Capitan
Try this:
bundle config build.nokogiri --use-system-libraries
bundle install
This works on rails 4.2.0, OS X 10.11.2 El Capitan and Xcode 7.2.1 installed
You will get while running bundler:
Installing nokogiri 1.6.7.2 with native extensions

An error occurred while installing nokogiri (1.5.2)

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

Resources