Require': Cannot Load Such File - 'Nokogiri\Nokogiri' (Loaderror) When Running 'Rails Server'

'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError) when running `rails server`

Nokogiri doesn't support Ruby 2.2 on Windows yet. The next release will. See https://github.com/sparklemotion/nokogiri/issues/1256

Nokogiri doesn't support native builds (e.g. with devkit) on Windows. Instead it provides gems containing prebuilt DLLs.

There's a discussion which you may want to join or watch on the topic of devkit build support here: https://github.com/sparklemotion/nokogiri/issues/1190

How to run rails console without nokogiri cannot load such file -- nokogiri/nokogiri (LoadError) error on Mac?

From your ruby -v, I see that you are in an Intel x86 Mac, but the gem that your trying to build (nokogiri-1.11.3-arm64-darwin) is for new Mac ARM M1 chips. If this is the cause, it means your are using precompiled gems.

Try uninstalling the gem, specify that you don't want to use precompiled gems, and reinstall.

gem uninstall nokogiri
bundle config set force_ruby_platform true
bundle install

Checkout this related docs

Why did I get LoadError: cannot load such file -- nokogiri?

Nokogiri is a dependency of one of the gems you're using.

The most common cause for your problem is using different OSes in development and in production, such as developing in Windows and deploying to Linux.

The simplest, but not the best, fix is to edit your Gemfile.lock and remove all -x86-mingw32 references from the gem versions. For instance, replace

nokogiri (1.6.6.2-x86-mingw32)

with

nokogiri (1.6.6.2)

Nokogiri will not be the only gem version you'll have to edit manually, so search for other gems with -x86-mingw32 in their versions. There will also be at least pg. It does not cause an error during deploy, it simply does not install if your Gemfile.lock was generated on Windows.

rails aborted! when running `rails new` and `rails s` giving load error for nokogiri and dlopen

The permission error probably means the gem has been installed by user root, doing something like sudo gem install, which means you have to use sudo to remove it too.

Now the nokogiri gem usually relies upon what is called native extensions, i.e. code that has to be compiled for a specific kind of platform.

Here we can see you have nokogiri installed for both x86_64-darwin and arm64-darwin.

Here darwin refers to your operating system (mac OS)

x86_64 is the code named for the 64bit versions of the intel family of processor, something also called amd64 because the first such processor was developed by AMD.

arm64 is another computer architecture, based on ARM which is often use in mobile phones and tablets because of it's lower energy consumption.

arm64-darwin refers to the new Apple Silicon architecture.

Now dlopen is the C api to load a shared-library (.so), and it reports clearly:

 could not use '.../nokogiri-1.11.2-arm64-darwin/l...' because it is not a compatible arch

So you know it's not usable on your system. which means you can probably safely remove it.

Additionaly, you could try using asdf, rbenv, rvm or something similar to manage your ruby versions, which will also keep your gems (depending on how you configure it) in your User's folder so you don't need to worry about sudo.

Why can't I load Nokogiri?

If you observe closely, the path starts with /home/askar/.rvm/rubies/ruby-1.9.3-p429 so the load path should be correct.

Your problem is that you used sudo which will do a gem installation for the system ruby. Try again without sudo, just

gem install nokogiri

to install gems for the current rvm ruby.



Related Topics



Leave a reply



Submit