Ruby on Rails:使用rmagic gem

以下是筆記:

一.修改Gemfile

gem 'rmagick', '2.13.2'

二.安裝必要套件

sudo apt-get install imagemagick libmagickcore-dev


然後bundle,這時會跑以下訊息


Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/home/eason/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no
Can't install RMagick 2.13.2. Can't find MagickWand.h.
*** 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/eason/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
Gem files will remain installed in /home/eason/.rvm/gems/ruby-2.0.0-p247/gems/rmagick-2.13.2 for inspection.
Results logged to /home/eason/.rvm/gems/ruby-2.0.0-p247/gems/rmagick-2.13.2/ext/RMagick/gem_make.out

An error occurred while installing rmagick (2.13.2), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.

原因為找不到  MagickWand.h

這時再安裝以下

sudo apt-get install libmagickwand-dev

然後再bundle一次應該就可以了

預設圖片
HC
文章: 241