RubyInstaller 2.2.1 and Rails - Rake cannot load Nokogiri

后端 未结 6 594
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 04:01

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 wh

相关标签:
6条回答
  • 2020-12-03 04:15

    The latest RC version of nokogiri supports Ruby 2.2:

    gem install nokogiri --pre
    
    0 讨论(0)
  • 2020-12-03 04:16

    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'

    0 讨论(0)
  • 2020-12-03 04:17

    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!

    0 讨论(0)
  • 2020-12-03 04:20

    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.

    0 讨论(0)
  • 2020-12-03 04:38

    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/
    
    0 讨论(0)
  • 2020-12-03 04:39

    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.

    0 讨论(0)
提交回复
热议问题