Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 859
s2t2 Avatar asked Apr 21 '15 20:04

s2t2


People also ask

How do you install gems you added to your Gemfile?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.

How do I use Gemfile in Ruby?

A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .

Is Nokogiri a ruby gem?

Imagine a tool and you most probably have it in your Ruby kit. One of the best gems for Ruby on Rails is Nokogiri which is a library to deal with XML and HTML documents. The most common use for a parser like Nokogiri is to extract data from structured documents.


2 Answers

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"
like image 176
infused Avatar answered Sep 28 '22 03:09

infused


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

like image 33
skalee Avatar answered Sep 28 '22 04:09

skalee