0
0

More than 1 year has passed since last update.

[Ruby][Gem] install nokogiri failed, Solved 解決法

Last updated at Posted at 2023-04-27

概要

CentOS 7で Railsのプロジェクト
(いつもの通り) bundle installすると
nokogiriのinstallに失敗する

( なぜか通らないという場合..

状況

大体nokogiri に必要なnativeライブラリはinstall済み
https://gist.github.com/trivektor/2415356
https://nokogiri.org/tutorials/installing_nokogiri.html

そして
gem install nokogiri -v '1.10.4'

とかすると一応成功して
nokogiri コマンドも使える

-> ただ、bundle installとかだと、失敗する..

問題

こういった場合、bundle install時のみ nativeライブラリのpathが上手く渡っておらず
buildに失敗している..
= optionで渡せばよいが..

解決法

今回の場合は、
普段 bundle install --path vendor/bundleしていたため
path指定の設定が残ったまま(~/.bundle/config) だったため
ずっと失敗していた..

= つまり、path指定を外すと bundle installが通る..

  • bundle config 設定を見直す
    ( いろいろ試していると増えて意図しない挙動になる
$ bundle config
Settings are listed in order of priority. The top value will be used.
build.nio4r
Set for the current user (/home/vagrant/.bundle/config): "--with-cflags=-std=c99"

build.mysql2
Set for the current user (/home/vagrant/.bundle/config): "--with-ldflags=-L/usr/lib64/"

build.puma
Set for the current user (/home/vagrant/.bundle/config): "--with-cflags=-Wno-error=implicit-function-declaration"

build.nokogiri
Set for the current user (/home/vagrant/.bundle/config): "--use-system-libraries"

( 不要な指定があれば除く

  • --path 指定を外す = bundle configから削除

普段path指定して bundle installしている場合だと思うが
--path指定付き(./vendor/bundle など..) だとうまくnative extensionのpathを見つけれられないようで
./.bundle/configファイルから削除 or optionで指定する必要がある

TLTD

path指定なしでbundle installすれば通る可能性

( 念のため bundle configで意図しない設定値がないか確認
不要なものあれば 該当部分削除

追記

その他に
エラーが出る場合がある

conflicting types for ‘canonicalize’
https://github.com/sparklemotion/nokogiri/issues/2105

->
どうやら最近のnokogiriのversion だと解決しているようだが、
Gemfile.lock に指定されてるのは 1.10.0 と古め
なので、
versionを上げるとよさそう..

Gemfile
# 最新を指定する
gem "nokogiri", "1.15.3"
# update nokogiri on Gemfile.lock
$ bundle update nokogiri

->
これで通った..

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0