"require": it is not possible to load such a file - "nokogiri \ nokogiri" (LoadError) when running `rails server`

I am running a clean installation of Ruby 2.2.1 on Windows 8.1 using DevKit. After installation, I run:

gem install rails rails new testapp cd testapp rails server 

leave everything else as default.

The process ends with an error in the last line, when instead of starting the server, an error message appears

 in 'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError) 

This happens every time, and I looked around and tried everything I found to fix it, but nothing has worked so far.

What is the problem and how do I get a simple Rails application to work?

+58
ruby ruby-on-rails nokogiri
Mar 12 '15 at 0:24
source share
4 answers

Nokogiri does not support Ruby 2.2 on Windows. The next issue will be. See https://github.com/sparklemotion/nokogiri/issues/1256

Nokogiri does not support built-in assemblies (e.g. with devkit) on Windows. Instead, it provides gems containing pre-created DLLs.

Here you can discuss or look at the devkit support topic: https://github.com/sparklemotion/nokogiri/issues/1190

+62
Mar 12 '15 at 10:50
source share
  • First uninstall the version of Nokogiri that you are currently using:

     gem uninstall nokogiri 
  • Download Nokogiri 1.6.6.2 (x64) or Nokogiri 1.6.6.2 (x86)

  • Install this version locally using:

     gem install --local C:\Users\$user$\Downloads\nokogiri-1.6.6.2-x64-mingw32.gem 

    or if you are using 32-bit Ruby:

     gem install --local C:\Users\$user$\Downloads\nokogiri-1.6.6.2-x86-mingw32.gem 

    The path may differ depending on where you downloaded the file.

Try starting the server again using ruby bin\rails server and it should work.

+36
Oct 12 '15 at 4:17
source share

I got Nokogiri working with Ruby 2.2 on Windows 10, with the answer from Mike Dalestios and Julios:

  • Find the latest version of Nokogiri at the Nokogiri github repo .
  • Run gem uninstall nokogiri .
  • Add the gem "nokogiri", ">= 1.6.7.rc" to your gemfile.
  • Run bundle install .
  • Run bundle update nokogiri if the bundle has blocked Nokogiri in some version.
+30
Oct 29 '15 at 9:20
source share

enter image description here

Fix

  • Package installation (receives Nokogiri files)
  • Go to ruby_dir\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2\ext\nokogiri
  • Open extconf.rb
  • Add dir_config('iconv').any? or pkg_config('libiconv') dir_config('iconv').any? or pkg_config('libiconv') in #376
  • Download MinGW64 and MSYS folders from Mega
  • Add them to your PATH on Windows (remove Devkit path refs - it doesn't work)
  • Download libxml2 , libxslt , iconv libraries (or here )
  • Run ruby extconf.rb --platform=ruby --n --use-system-libraries link to loaded libraries
  • Run make
  • Run make install



Actions

Package installation

The first step is bundle.

This will put the nokogiri on your computer without launching the pre-packaged compiler (which basically does not work on Windows).

This will show the Nokogiri as installed:

enter image description here

Overview

Go to the nokogiri folder to find ext/nokogiri/extconf.rb :

enter image description here

Open extconf.rb

... and add dir_config('iconv').any? or pkg_config('libiconv') dir_config('iconv').any? or pkg_config('libiconv') in #376

enter image description here

The standard Nokogiri sets "rely" on libxml2 include iconv - we need to explicitly define it, otherwise iconv.h is missing errors will occur.

Add Toolchain

Do not use Devkit for this - it does not work.

You need MinGW :

enter image description here

I copied my exact MinGW64 and MSYS64 folders to Mega (key !FJtcq25l-QMsNltCxllMhc1IGqORvap8xv8gWxSUbDA ):

enter image description here

Add to PATH

This gives access to gcc and make (both required):

enter image description here

Remove the Devkit link from your path and add the following:

  • MINGW64_PATH / bin
  • MSYS64_PATH / bin

Download Libs

I added libraries to Mega:

enter image description here

You will unpack them here:

enter image description here

All libraries from this source .

Run extconf.rb

Once the libs libraries are on your system, you can run ruby extconf.rb to configure the build:

enter image description here

32bit

ruby extconf.rb --platform=ruby -N -- --use-system-libraries --with-xml2-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxml2-2.9.2-win32-x86 --with-xml2-include=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxml2-2.9.2-win32-x86/include/libxml2 --with-iconv-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/iconv-1.14-win32-x86 --with-xslt-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxslt-1.1.28-win32-x86

64bit

#64 ruby extconf.rb --platform=ruby -N -- --use-system-libraries --with-xml2-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxml2-2.9.2-win32-x86_64 --with-xml2-include=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxml2-2.9.2-win32-x86_64/include/libxml2 --with-iconv-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/iconv-1.14-win32-x86_64 --with-xslt-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxslt-1.1.28-win32-x86_64

make

enter image description here

This can lead to errors / warnings if it says β€œ Error 1 (ignored) ”, this should be fine.

After that use make install :

enter image description here

Then go to install Rails and run rails s :

enter image description here




Explanation

To give context:

Ruby 2.2+ on Windows does not compile the extensions required by Nokogiri.

Gem extensions are additional dependencies (libraries) that it uses.

They are created when installing a gem:

enter image description here




Extensions

The absence of extensions prevents Nokogiri from starting.

Extensions exist in the gem ext folder ( you can read about them here ):

enter image description here

Mysql2 , RMagick , PGSQL , nokogiri , etc. all use extensions / libraries.

That's why - on Windows - when installing the gem, you should use special switches ( --with-opt-dir ). This gives Ruby / shell / ( cmd ) the required lib / include directories needed to build the gem files (this is equivalent to how PATH works.)

On Linux / Mac these directories are managed using the appropriate package managers ( brew / apt-get ). Windows does not, so you need to install extensions manually.

Since Windows does not have a standard set of libraries, you must download them yourself. You must also create them yourself (which is difficult).

Fix for installing Nokogiri - using the right libraries and creating tools for installing gem.




Build

The difference with Ruby 2.2+ is that the gem will β€œinstall” without showing any exceptions. You think that it is installed, only to find Rails, it does not load (hence the error nokogiri/nokogiri.so ).

This means that you must make sure that you have the files in your system and run the compiler to install them.

The above documentation should show how to do this.

+4
Nov 08 '15 at 12:19
source share



All Articles