Rubyinstaller 2.2.1 and Rails - Rake Cannot Load Nokogiri

RubyInstaller 2.2.1 and Rails - Rake cannot load Nokogiri

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.

require nokogiri issue with ruby

I'm afraid nokogiri won't work for the combination of Ruby 2.2 and mingw. According to https://github.com/sparklemotion/nokogiri/issues/1256, it is currently only supported for Ruby 1.9, 2.0 and 2.1.

There is a workaround with manual install of libraries, as described in RubyInstaller 2.2.1 and Rails - Rake cannot load Nokogiri, but it seems to be a bit tricky. So if Ruby 2.2 is not that critical for you, you may want to downgrade to Ruby 2.1.

And as a general recommendation -- development on Ruby/Rails using Windows it not really optimal, consider switching to Linux

In Windows, rails s gives 3 different errors, I fix one and get a bunch more

One option is downgrading ruby to a version that is stable/working with windows. The other option is installing a linux VM and installing Ruby there.

You need to install a version of Ruby that is stable with Windows.

Not the latest version of Ruby. As of writing the latest is 2.2.2 and not stable with Windows.

And even if you are on a 64bit machine, the stable Ruby for Windows is a 32bit.

You want Ruby 2.1.X e.g. Ruby 2.1.6 (the latest 2.1.x is fine, 2.1.6) And you want the 32bit version

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.1.6.exe

That is mentioned here http://rubyinstaller.org/downloads/ "we recommend you use Ruby 2.1.X installers. These provide a stable language and a extensive list of packages (gems) that are compatible and updated.

However, not all packages (gems) are maintained. Some older packages may not be compatible with newer versions of Ruby and RubyInstaller.

The 64-bit versions of Ruby are relatively new on the Windows area and not all the packages have been updated to be compatible with it. To use this version you will require some knowledge about compilers and solving dependency issues, which might be too complicated if you just want to play with the language."

Take note of that instruction

So remove any current Ruby you have.

To remove Ruby, you go to the start menu..Ruby.. and click Uninstall.

That should uninstall Rails too.

And remove any devkit. The devkit executable installs by extraction to a folder you specify so just rmdir/remove that folder.

Now install that stable ruby.. 2.1.6 32bit
Install rails and the devkit

The command to install rails

gem install rails

An to install the devkit make sure you have the correct one

e.g.

http://rubyinstaller.org/downloads/

WHICH DEVELOPMENT KIT?
....

Ruby 1.8.6 to 1.9.3: tdm-32-4.5.2

Ruby 2.0.0 and above (32bits): mingw64-32-4.7.2

Ruby 2.0.0 and above x64 (64bits): mingw64-64-4.7.2

So you want

Ruby 2.0.0 and above (32bits): mingw64-32-4.7.2

Look at the available devkits

DEVELOPMENT KIT

For use with Ruby 1.8.7 and 1.9.3:

DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

For use with Ruby 2.0 and above (32bits version only):

DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe

For use with Ruby 2.0 and above (x64 - 64bits only)

DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe

You want

DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

For use with Ruby 2.0 and above (32bits version only):

http://dl.bintray.com/oneclick/rubyinstaller/DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe

Follow the instructions from here to install devkit https://github.com/oneclick/rubyinstaller/wiki/Development-Kit

So say you put it in c:\devkit

c:\devkit>ruby dk.rb init

c:\devkit>ruby dk.rb install

you can run this command though i don't think it's necessary
c:\sdfsd>gem install json --platform=ruby

so now you have ruby and rails and the devkit installed

rails new <project name>

cd <project name>

bundle install

rails s

http://localhost:3000 (in your browser)

and it says 'welcome aboard'

Ruby on Rails - cannot load such file -- mysql2/2.2/mysql2 (LoadError)

The problem is that the mysql2 gem is not installing with its native dependencies. In previous versions of Ruby, this would have triggered the unable to build native gem extension error:

Sample Image

Something has changed in Ruby 2.2 so that you can install the gem without it building the native extension. This does not mean the problem is resolved however - and so you have to ensure you install the gem with the appropriate dependencies.

Tutorial:

  1. Download C-Connector from MYSQL (note your version of Ruby -- if you're using 64 bit, download the 64 bit version)

  2. Unzip / Install the MYSQL C-Connector folder onto your HDD (don't have any spaces in the path)

  3. Run the following command: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/your-mysql-connector-path"'

  4. This should install the gem with the files it needs

  5. Then you can copy libmysql.dll from C:/your-mysql-connector-path -> c:/your-ruby-install/bin`

The difference between this install and the previous one will be that this should mention that the native gem extensions are being installed (This could take a while), which suggests that Ruby is looking at the library.

This time, if it installs correctly, it should work for you.

--

If you're still seeing an error, you'll have to uninstall any existing versions of the mysql2 gem on your system:

How to install mysql2.

If you're getting an error, you just need to type gem uninstall mysql2, select all and then repeat the steps above.



Related Topics



Leave a reply



Submit