How to "gem install nokogiri -- --use-system-libraries" via Gemfile

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


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"