(Ruby 2.5.1) Windows Fix – "Cannot Load Such File – Sqlite3/Sqlite3_native (LoadError)"

When you use Home windows, you have to recognize that there are a number of gems which require exterior libraries to be able to be “constructed” correctly.

These exterior libraries are typically not current in your system and are required to be put in (and referenced) to get them working. That is why the likes of the MYSQL2 and RMagick gems are seen as “troublesome” to put in.

When you’re utilizing SQLite3, issues are barely totally different.

This gem has a number of “builds” which are supposed to present performance throughout plenty of platforms (Home windows included). While this works in earlier variations of Ruby, it does not work for Ruby 2.5.1+ – therefore the error you are seeing…

can not load such file — sqlite3/sqlite3_native (LoadError)

The error is brought on by the set up & tried utilization of the “mingw32” model of the gem. This model of the gem is pre-compiled with the SQLite core recordsdata, however has points when getting used with the later variations of Ruby.

The answer is to put in the gem for the “ruby” platform (which nonetheless works high-quality in Home windows):

gem set up sqlite3 –platform=ruby

This can set up the “native” model of the gem with all the suitable recordsdata and so forth – however will not use any of the platform-specific performance that comes with the likes of the mingw32 model.

This can work 100% out of the field.

Nevertheless, there’s one other downside. When you use “bundler”, it is going to typically override the native gem set up in favour of a platform-specific one. Which means that in case you run bundle replace / bundle set up, it is going to possible set up the sqlite3 gem with mingw32 platform.

On this occasion, it’s good to uninstall *any* references to the latter by utilizing “gem uninstall”. Here is what sometimes occurs (for us):

  • bundle replace [installs sqlite3]
  • gem uninstall sqlite3 [shows selection]
  • take away “mingw32” variant
  • rails s [should work 100%]

This can get the system working with the gem.

The large downside is that everytime you use the “mingw32” model of the gem, it is going to have a set of references/calls that are designed particularly to name specific parts of the gem.

In Ruby 2.5.1+ – for no matter cause – these calls will not be solely used to make sure that the system is ready to take advantage of progress, therefore the error you are seeing. To repair this, you want to have the ability to basically “drive” your system to solely use the “ruby” variant of the gem.

Clearly, in case you’re utilizing the likes of Linux or Mac as a growth atmosphere – one of these factor could possibly be comparatively merely averted. However the place’s the enjoyable in doing one thing that is straightforward? Use Home windows!

Leave a comment

Design a site like this with WordPress.com
Get started