12

recently I installed Ruby 2.2.1 with the new RubyInstaller on Windows. To check whether everything was working I went into a rails app and ran bundle install which was working fine. However, when I ran the tests with bunle exec rake test, I got the following errors:

rake aborted!
LoadError: cannot load such file -- nokogiri/nokogiri
D:/Dev/Grummle/config/application.rb:7:in `<top (required)>'
D:/Dev/Grummle/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- nokogiri/2.2/nokogiri
D:/Dev/Grummle/config/application.rb:7:in `<top (required)>'
D:/Dev/Grummle/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

Bundler says that it is Using nokogiri 1.6.5. Also, the rake task is working fine with Ruby 2.1.5. I appreciate ideas on how to resolve the issue. Thanks! :)

Mystler
  • 183
  • 1
  • 1
  • 6

6 Answers6

11

I think I got it working on my system:

enter image description here

I don't know what was done to get this working, but I'll share what I did:

  1. The problem for Windows with Ruby 2.2+ & Nokogiri is that the gem doesn't compile. Nokogiri requires libXML, libxslt & libiconv in order for it to work. These are nominally compiled at gem install, but for whatever reason, this does not occur in Ruby 2.2+.

  2. Therefore, in order to install the gem (this is exactly the same situation with mysql2 and rmagick), you need the system dependencies (mentioned above).

  3. From Ruby 2.2+, it seems that gems will "install" even if they don't have their dependencies on the system (as opposed to refusing the install by not building native extensions in previous versions). The new runtime errors which appear include cannot load such file -- mysql2/2.2/mysql2 (LoadError) and the corresponding one for nokogiri (cannot load such file -- nokogiri/nokogiri).

  4. With this in mind, you have to appreciate how the gems are installed & work. A good example is the mysql2 gem - to install it, you need to download the MYSQL C-Connector plugin and then link to the dependency with the following code: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-path"'

  5. With Nokogiri, you need to have libxml, libiconv and libxslt on your system. I learnt that from this post:

enter image description here

  1. The problem arises here. I am not 100% sure what I did here to get this working (even temporarily). I know that I installed the Nokogiri gem, and then set about compiling the gem using ruby extconf.rb (which is what the gem does anyway). Considering this what I feel worked, I'll explain how this was performed.

  2. The gem will typically download the libraries through install. It keeps these in the ext/tmp/ports folder. For my system, the download of libiconv was what prevented the install from completing (error about CPPFLAGS). With this in mind, I figured that if the gem installed, and if it was trying to build, it would be prudent to get the dependencies installed.

  3. Thus, I worked on the ruby ext/extconf.rb process using the --use-system-libraries switch:

"...\nokogiri>ruby extconf.rb --platform=ruby -N --use-system-libraries --w ith-xml2-dir=C:\Users\Richard\Downloads\Ruby\libxml2-2.7.8.win32 --with-xml2-include=C:\Users \Richard\Downloads\Ruby\libxml2-2.7.8.win32\include --with-xml2-lib=C:\Users\Ric hard\Downloads\Ruby\libxml2-2.7.8.win32\lib --with-iconv-dir=C:\Users\Richard\Do wnloads\Ruby\iconv-1.9.2.win32 --with-iconv-include=C:\Users\Richard\Downloads\R uby\iconv-1.9.2.win32\include --with-iconv-lib=C:\Users\Richard\Downloads\Ruby\i conv-1.9.2.win32\lib --with-zlib-dir=C:\Users\Richard\Downloads\Ruby\zlib-1.2.5"

I coupled this with downloading the aforementioned libraries (and some which didn't work):

enter image description here

  1. I don't have a record of the output of the above command, but I am pretty sure it built the extensions as required, ending in saying a "Makefile" had been compiled. When a Makefile is available, you should be able to use nmake (Windows 7.1 SDK) or make (MingW) to get it to run. I did this, and it seemed to work.

  2. I tried loading the server today, and it appeared to work.

That's the best I have right now.

I am available to answer comments etc as required.

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • 1
    I think downgrading to Ruby 2.1 or developing on a Linux system is the best solution for now. I'm stuck with this error while trying to learn Rails. It's quite annoying as it is time consuming. It makes me wonder if Rails is really a stable framework at all. Anyway, were you able to repeat your solution on different Windows 64bits systems ? –  Apr 18 '15 at 11:45
  • Hey man, I haven't tried on different systems. I had to get some other things (MingW64 compilers etc) and just went at it. I didn't see why we couldn't have Nokogiri install if it uses the same dependencies. My skype is "gorkite" - if you add me, I'll see if we can get it working for you – Richard Peck Apr 19 '15 at 14:44
  • 1
    Rails *is* a stable framework, this is a *Ruby* problem, and Windows is famously not friendly for development. We do a lot of gfx, so I love to have the accessibility, thus making it vital to have it working on Win. – Richard Peck Apr 19 '15 at 14:45
9

Until they release a proper nokogiri release for Ruby 2.2, I'd like to share with you all, some steps to get it running.

Credits for Paul Grant and Daniel Rikowski for their help!

First, I must say I'm running Ruby 2.2.2p95 (32bits) on Windows 8.1 (64 bits) and Rails 4.2.3 installed (and Cygwin shell)

1) uninstall the nokogiri gem (you'll need to confirm because many gems depend on it)

2) download the nokogiri gem compiled on ruby 2.2 by Paul Grant (kudos for him) here: https://github.com/paulgrant999/ruby-2.2.2-nokogiri-1.6.6.2-x86-x64-mingw32.gem

3) installed the local gem ( gem install --local path/to/gem ) 32 bit version (in my case)

if you try to load rails here, bcrypt will fail, so, as posted by Daniel Rikowski, you can build your on bcrypt_ext.so file.

4) be sure that you have DevKit on your path (/devkit/bin and /devkit/mingw/bin)

5) go to bcrypt ext/mri gem subfolder: (I'm using Cygwin)

cd /cygdrive/c/Ruby22/lib/ruby/gems/2.2.0/gems/bcrypt-3.1.10-x86-mingw32/ext/mri

6) call ruby extconf.rb (to generate a Makefile)

7) just call make

(it will output many files including a bcrypt_ext.so file)

8) copy bcrypt_ext.so to /cygdrive/c/Ruby22/lib/ruby/gems/2.2.0/gems/bcrypt-3.1.10-x86-mingw32/lib/2.2 folder. You have to create this subfolder.

That's it! Now just start your rails server. Working like a charm!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Fernando Vieira
  • 3,177
  • 29
  • 26
5

Nokogiri doesn't exist yet for Ruby 2.2 on windows.

https://github.com/sparklemotion/nokogiri/issues/1256

Essentially, nokogiri is provided preocompiled for specific ruby versions, and 2.2 isn't one of those versions yet. compiling nokogiri for windows is overly complicated.

spotter
  • 1,178
  • 1
  • 9
  • 19
  • the problem is that previous version of rubyinstaller contained a little bug which caused seg fault so many switched to rubyinstaller 2.2 and are now facing this other problem.... :\ – Redoman Apr 14 '15 at 20:31
2

The latest RC version of nokogiri supports Ruby 2.2:

gem install nokogiri --pre
  • 1
    Yes! This worked form. Had to `gem uninstall nokogiri` all versions and executable first. Also use the Command Prompt (Admin). – Danny G Feb 01 '16 at 15:24
0

You can try to use cross-compilled gem. For me works fine.

  1. Remove all versions of nokogiri installed previously

    gem uninstall nokogiri

  2. Download gem from https://github.com/paulgrant999/ruby-2.2.2-nokogiri-1.6.6.2-x86-x64-mingw32.gem

  3. Install using one of the next commands:

    For 64bit Ruby: gem install --local nokogiri-1.6.6.2-x64-mingw32.gem

    For 32bit Ruby: gem install --local nokogiri-1.6.6.2-x86-mingw32.gem

  4. Lock version of nokogiri i your Gemfile:

    gem 'nokogiri', '1.6.6.2'

Sergey Bezugliy
  • 580
  • 7
  • 23
0

I had to install the nokogiri version 1.6.3.1 for this ruby version, I put this and worked for me:

 gem install nokogiri -v 1.6.3.1 -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2/
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73