20

There is a known error installing the latest version of Nokogiri. The workaround is to manually install using

gem install nokogiri -- --use-system-libraries

But how can this be done via the Gemfile?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
s2t2
  • 2,462
  • 5
  • 37
  • 47

2 Answers2

39

Run

bundle config build.nokogiri --use-system-libraries

After running this command, every time Bundler needs to install the nokogiri gem, it will pass along the flags you specified.

It remembers this setting by adding an entry to your ~/.bundle/config file:

---
BUNDLE_BUILD__NOKOGIRI: "--use-system-libraries"
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
infused
  • 24,000
  • 13
  • 68
  • 78
  • cool. are there any differences or considerations between using this approach on local dev environment (mac os) and on production dev environment (linux)? – s2t2 Apr 21 '15 at 21:39
  • 3
    FYI I added the config file to my application directory, per the [docs](http://bundler.io/v1.3/man/bundle-config.1.html) – s2t2 Apr 21 '15 at 21:52
  • 2
    FYI I needed to REMOVE this setting in order to make nokogiri 1.8.4 (used by `slather`) work again on macOS High Sierra. – fabb Sep 21 '18 at 07:16
5

System-wide way:

bundle config --global build.nokogiri --use-system-libraries

Saves configuration to $HOME/.bundle/config (this path is configurable), so that it is shared by all projects.

The --global parameter is default, hence one may omit it.

Application-wide way

bundle config --local build.nokogiri --use-system-libraries

Saves configuration to <project_root>/.bundle/config, so that it is confined to gemfiles contained in this directory.

Reverting

bundle config --delete build.nokogiri

Removes build.nokogiri setting from both global and local configuration files.

See also

Bundler docs: https://bundler.io/man/bundle-config.1.html

skalee
  • 12,331
  • 6
  • 55
  • 57