[![enter image description here][1]][1]
#Fix
1. Bundle install (gets Nokogiri files)
2. Browse to `ruby_dir\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2\ext\nokogiri`
3. Open `extconf.rb`
1. Add `dir_config('iconv').any? or pkg_config('libiconv')` to `#376`
2. [Download `MinGW64` & `MSYS` folders from Mega][2]
3. Add them to `PATH` in Windows (remove `Devkit` path refs - it doesn't work)
4. [Download `libxml2`,`libxslt`, `iconv` libraries][3] (or [here][4])
5. Run `ruby extconf.rb --platform=ruby --n --use-system-libraries` referencing downloaded libraries
6. Run `make`
7. Run `make install`
---
#Steps
**Bundle Install**
First step is to *bundle*.
This will put the `nokogiri` gem on your machine without running the pre-packaged compiler (which mostly doesn't work in Windows).
This will show Nokogiri as *installed*:
[![enter image description here][5]][5]
**Browse**
Browse to the `nokogiri` folder, to find `ext/nokogiri/extconf.rb`:
[![enter image description here][6]][6]
**Open `extconf.rb`**
... and add ` dir_config('iconv').any? or pkg_config('libiconv')` to `#376`
[![enter image description here][7]][7]
Standard Nokogiri installs "rely" on the `libxml2` inclusion of `iconv` - we need to explicitly define it, otherwise `iconv.h is missing` errors will occur.
**Add Toolchain**
Don't use `devkit` for this - it doesn't work.
You need `MinGW`:
[![enter image description here][8]][8]
I have zipped my exact `MinGW64` and `MSYS64` folders [on Mega][9] (key: `!FJtcq25l-QMsNltCxllMhc1IGqORvap8xv8gWxSUbDA`):
[![enter image description here][10]][10]
**Add to PATH**
This gives access to `gcc` & `make` (both required):
[![enter image description here][11]][11]
Remove the `devkit` ref from your path, and add the following:
> - MINGW64_PATH/bin
> - MSYS64_PATH/bin
**Download Libs**
I have added the libs to Mega:
[![enter image description here][12]][12]
You will unzip them here:
[![enter image description here][13]][13]
All the libs are from [this source][4].
**Run `extconf.rb`**
Once libs are on your system, you can run `ruby extconf.rb` to configure the build:
[![enter image description here][14]][14]
> **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][15]][15]
This may create errors / warnings, as long as it says "`Error 1 (ignored)`", it should be okay.
Following that, use `make install`:
[![enter image description here][16]][16]
Then browse to your Rails installation and run `rails s`:
[![enter image description here][17]][17]
---
#Explanation
To give context:
Ruby 2.2+ on Windows doesn't compile the *extensions* Nokogiri requires.
The *extensions* of a gem are the extra dependencies (libraries) it uses.
They are built when you *install* the gem:
[![enter image description here][18]][18]
---
**[Extensions][19]**
Lack of extensions is preventing Nokogiri from running.
Extensions exist in the `ext` folder of a gem ([you can read about them here][19]):
[![enter image description here][20]][20]
`Mysql2`,`RMagick`,`PGSQL`, `Nokogiri` etc *all* use extensions/libraries.
This is why - on Windows - you have to use custom switches (`--with-opt-dir`) when installing the gem. This gives Ruby / the shell / (`cmd`) the required `lib` / `include` directories required to build the gem's files (it's the equivalent of how [`PATH`][21] works).
On `Linux`/`Mac`, these directories are managed with the respective package managers (`brew`/`apt-get`). Windows does not have this, so you have to install the extensions manually.
Because Windows does not have a standard set of libraries, you have to download them yourself. You also have to *build* them yourself (which is tricky).
The fix for Nokogiri install is to use the right libraries and build tools to get the gem installed.
---
**Build**
The difference with Ruby 2.2+ is the gem will "install" without showing any exceptions. You think it has installed, only to find Rails does **not** load (hence the `nokogiri/nokogiri.so` error).
This means you have to make sure you have the files on your system, and run the compiler to install them.
The above documentation should show you how to do that.
[1]:
[2]:
[To see links please register here]
[3]:
[To see links please register here]
[4]:
[To see links please register here]
[5]:
[6]:
[7]:
[8]:
[9]:
[To see links please register here]
[10]:
[11]:
[12]:
[13]:
[14]:
[15]:
[16]:
[17]:
[18]:
[19]:
[To see links please register here]
[20]:
[21]:
[To see links please register here]