[RUBY] [Rails] How to install ImageMagick (RMajick)

What is ImageMagick?

ImageMagick is software for manipulating and displaying images. It supports more than 100 types of image file formats such as GIF, JPEG, PNG, PDF, and TIFF, and has many functions necessary for converting and editing images from programs. It is used when you want to create a web service that processes and transforms images, such as "upload image → generate thumbnail".

Japanese manual on how to use Imagemagick

Introduction

I want to use ImageMajick for various image processing.

But this is not Ruby's In Ruby, it seems that it can be used with a gem called RMagick, so put this in.

#add to
gem 'rmagick'

# => bundle install

However, the following error occurs.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/uenoyuuki/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rmagick-4.0.0/ext/RMagick
/Users/uenoyuuki/.rbenv/versions/2.5.0/bin/ruby -r ./siteconf20190916-2480-i0d2pg.rb extconf.rb
checking for brew... yes
checking for clang... yes
checking for pkg-config... yes


ERROR: Can't install RMagick 4.0.0. Can't find ImageMagick with pkg-config


*** 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=/Users/uenoyuuki/.rbenv/versions/2.5.0/bin/$(RUBY_BASE_NAME)

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/uenoyuuki/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/rmagick-4.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/uenoyuuki/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rmagick-4.0.0 for inspection.
Results logged to /Users/uenoyuuki/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/rmagick-4.0.0/gem_make.out

An error occurred while installing rmagick (4.0.0), and Bundler cannot continue.
Make sure that `gem install rmagick -v '4.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

It seems that you need to install Imaga Majick itself first.

Since the OS is ʻAmazon-Linux, install using yum`.

$ sudo yum -y install ImageMagick ImageMagick-devel
#Add again
gem 'rmagick'

# => bundle install

success…!

Failure story

As a failure to insert ImageMagick, I used to use a package manager as a glue, so I didn't know the difference between them, and it took a long time.

# Amazon-Not available on Linux

# Mac OS
$ brew install imagemagick@6

# Ubunts
$ sudo apt-get install imagemagick libmagick++-dev

I don't know what OS it is! It shouldn't happen, At worst, you can still check the OS.

$ cat /etc/*-release

reference

Various ways to specify Variant for Active Storage Using RMagick with Rails Install [Gem] RMagick on CentOS The story that I solved the error when trying to use rmagick on Cloud9 Cannot install apt command

Recommended Posts

[Rails] How to install ImageMagick (RMajick)
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to install Font Awesome
How to install ImageMagick on Windows 10
[Rails] How to install Font Awesome
How to install Swiper in Rails
How to write Rails
How to install Docker
How to install MySQL
How to install ngrok
[Ruby on Rails] How to install Bootstrap in Rails
[Rails] How to use enum
How to read rails routes
How to install Boots Faces
How to use rails join
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
How to install JDK8-10 (Mac)
[Rails] How to use Scope
[Rails] How to install a decorator using gem draper
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
Rails new fails to install mysql
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[rails] How to display db information
How to install JMeter for Mac
[Rails] How to prevent screen transition
How to install ruby through rbenv
[How to install Spring Data Jpa]
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Rails] How to speed up docker-compose
Super rough! How to install Dagger2
[Rails] How to add new pages
How to install Bootstrap in Ruby
[Rails] How to write exception handling?
[Rails] How to use Active Storage
How to install WildFly on Ubuntu 18.04
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails
Super easy in 2 steps! How to install devise! !! (rails 5 version)
[Introduction to Rails] How to use render
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
How to install Pry after building Rails development environment with Docker
How to change app name in rails
How to use custom helpers in rails
Install Webpacker and Yarn to run Rails
How to install Play Framework 2.6 for Mac
[Ruby on Rails] How to use CarrierWave