【Ruby x Linux】Gem kakasiのインストール方法
ec2(linux os)でkakasiをrubyで使えるようにするgem、kakasi_ffiインストールするときに結構詰まったのでその解決方法。
kakasiとは
漢字とかひらがな、それら混じったものとかを一括でカタカナ、ひらがな、ローマ字などに直してくれます。
以下公式サイト説明
KAKASI は、 漢字かなまじり文をひらがな文やローマ字文に変換することを目的として 作成したプログラムと辞書の総称です。
kakasi_ffiについて
問題点
local(Mac Siera)では公式サイトの手順に従えばすんなりいくが、Linux上で同じようにすると、kakasiのインストールはうまくいくが、gem kakasiのインストールがうまくいかない。
以下エラーログ。
Building native extensions. This could take a while... ERROR: Error installing kakasi: ERROR: Failed to build gem native extension. current directory: /home/***/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/kakasi-1.0.2/ext/kakasi-config /home/***/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170624-20059-1n6555o.rb extconf.rb checking fiddle... yes checking for kakasi... failed -- libkakasi is not found *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/home/***/.rbenv/versions/2.4.0/bin/$(RUBY_BASE_NAME) --with-kakasi-dir --without-kakasi-dir --with-kakasi-include --without-kakasi-include=${kakasi-dir}/include --with-kakasi-lib --without-kakasi-lib=${kakasi-dir}/lib extconf failed, exit code 1
libkakasi is not found ?(怒)
解決方法
問題は、/usr/local/libにパスが通っていなかったため。
kakasiはインストール後、/user/local/lib配下に入るが、パスが通っていないためアクセスできなかった。
以下のように解決した。
- vi /etc/ld.so.conf
- /usr/local/lib と追記
- ldconfigでライブラリキャッシュをクリア
システム全体でライブラリパスを設定したい場合は、/etc/ld.so.confファイルにライブラリへのパスを追記します。