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! :)
I think I got it working on my system:
I don't know what was done to get this working, but I'll share what I did:
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+
.
Therefore, in order to install the gem (this is exactly the same situation with mysql2
and rmagick
), you need the system dependencies (mentioned above).
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
).
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"'
With Nokogiri
, you need to have libxml
, libiconv
and libxslt
on your system. I learnt that from this post:
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.
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.
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):
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.
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.
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!
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.
The latest RC version of nokogiri supports Ruby 2.2:
gem install nokogiri --pre
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With