DEV Community

m-yoshimo
m-yoshimo

Posted on

2 1

Ubuntu 18.04 にあげたら Rails で libMagickCore.so.2 が見つからない

先日、WSL の Ubuntu 環境を 16.04 から 18.04 にアップグレードしたのですが、いざ rails を起動しようとすると libMagicCore.so.2 が見当たらないとのこと。

$ bundle exec rails s
rails aborted!$
LoadError: libMagickCore-6.Q16.so.2: cannot open shared object file: No such file or directory - /home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/rmagick-2.16.0/lib/RMagick2.so$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/rmagick-2.16.0/lib/rmagick_internal.rb:12:in `<top (required)>'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'$
/home/m-yoshimo/bundle/MyApp/ruby/2.4.0/gems/rmagick-2.16.0/lib/rmagick.rb:1:in `<top (required)>'$
/mnt/c/work/repositories/MyApp/config/application.rb:10:in `<top (required)>'$
/mnt/c/work/repositories/MyApp/Rakefile:4:in `require'$
/mnt/c/work/repositories/MyApp/Rakefile:4:in `<top (required)>'$

libMagicCore を探しても見当たらない

$ ls /usr/lib/libMagic*
ls: '/usr/lib/libMagic*' にアクセスできません: そのようなファイルやディレクトリはありません
$ ls /usr/local/lib/libMagi*
ls: '/usr/local/lib/libMagi*' にアクセスできません: そのようなファイルやディレクトリはありません

と思ったら、/usr/lib/x86_64-linux-gnu に移動してました

$ ls /usr/lib/x86_64-linux-gnu/libMagick*
/usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.a         /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.a
/usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.la        /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.la
/usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.so        /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so
/usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.so.3      /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so.3
/usr/lib/x86_64-linux-gnu/libMagickCore-6.Q16.so.3.0.0  /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so.3.0.0

とりあえず PATH を通してあげて

export PATH=/usr/lib/x86_64-linux-gnu:${PATH}

rmagick はインストール時にロードする libMagicCore のファイルパスを記憶するようなので、一度 rmagick を削除してから、再度 bundle install しなおす

$ bundle exec gem uninstall rmagick

Select gem to uninstall:
 1. rmagick-2.16.0
 2. rmagick-3.0.0
 3. All versions
> 3
Successfully uninstalled rmagick-2.16.0
Successfully uninstalled rmagick-3.0.0

$ bundle install
...
Fetching rmagick 2.16.0
Installing rmagick 2.16.0 with native extensions
...
Bundle complete! 80 Gemfile dependencies, 375 gems now installed.
Bundled gems are installed into `/home/m-yoshimo/bundle/MyApp`

これで無事に起動できるようになりましたとさ

$ bundle exec rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.3-p205), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

ここまで書いて気付いたのですが、普通に過去に同じ経験した人がいたようです。
https://qiita.com/aiyu427/items/9231aab85c3b3b8ac227

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay