ImageMagick and Paperclip on Rails only accepts bmp file - ruby-on-rails

I'm trying to set up a rails app with paperclip and ImageMagick on Ubunutu 10.10, I have managed to make it work but only with bmp files, when i try to upload any other kind of file I get the error:
Image Paperclip::CommandNotFoundError
Image Paperclip::CommandNotFoundError
I thought it had something to do with ImageMagic so I found this old tutorial
http://www.randycullom.com/chatterbox/archives/2006/12/installing_imag.html
So I uninstall ImageMagick, installed jpg,tiff and png libraries, on jgp library I used
./configure --enable-shared
...
And then install ImageMagic with configure
./configure --enable-lzw=yes --enable-shared=yes --disable-static --without-perl
make
sudo make install
and the error still apears, on my enviroment.rb I have
Paperclip.options[:command_path] = "/usr/local/bin/"
Which is the path than running 'which convert' gave me, on gem file:
gem "paperclip", "~> 2.3"
gem 'rmagick'
What am I missing? Help would be much appreciated.

On Ubuntu, you can usually safely intall ImageMagick via apt-get (or aptitude). Normally I do:
sudo apt-get install imagemagick
sudo apt-get install libmagick9-dev [deprecated]
sudo gem install rmagick
Edited
use instead of libmagick9-dev
sudo apt-get install graphicsmagick-libmagick-dev-compat

Update from #bartuzz comment
Ubuntu 14.04:
sudo apt-get install libmagickcore-dev libmagickwand-dev

Following on from the other answers (#Callmeed, #arturtr), for Ubuntu 14.04
sudo apt-get install imagemagick
sudo apt-get install graphicsmagick-libmagick-dev-compat
sudo apt-get install libmagickcore-dev libmagickwand-dev
worked for me, but installing rmagick without the sudo
gem install rmagick

Ubuntu 16.04:
sudo apt-get -y install imagemagick libmagickcore-dev libmagickwand-dev

Related

Rails: Error installing rmagick - ERROR: Failed to build gem native extension

I am trying to run one project on my local machine. I installed Ruby and Rails on my Mac OS system. It is working properly. I can create a new project and can run it properly without any error, but when I try to run the existing project it says that we have to bundle install. When I run that command I get the following error:
"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."
When I run gem install rmagick -v '2.13.2' it gives me the following error:
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc-4.2... yes
checking for Magick-config... no
Can't install RMagick 2.13.2. Can't find Magick-config in /usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin
*** 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=/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rmagick-2.13.2/ext/RMagick/gem_make.out
I have searched and did not find an answer anywhere.
For Ubuntu, I used the ff. based on this link:
$ sudo apt-get install libmagick++-dev
On a mac (the below code works on OSX Mavericks):
brew install imagemagick
gem install rmagick
On Mac you can try this:
$ brew unlink imagemagick
$ brew install imagemagick#6 && brew link imagemagick#6 --force
$ gem install rmagick
I have solved this problem by installing imagemagic:
sudo apt-get install imagemagick
and then install libmagick package:
sudo apt-get install libmagick++-dev
For Linux Fedora, I got same error and fixed with below two commands:
yum install ImageMagick
gem install rmagick
For Centos install ImageMagick-devel package. using below commands:
yum install ImageMagick-devel
gem install rmagick
First, make sure you've installed Imagemagick :
$ sudo apt-get install imagemagick
Now, it can build the gem native extension.
Then, install the Rmagick gem :
$ sudo gem install rmagick
here's what i did on 16.04,
sudo apt-get install libmagickwand-dev
sudo apt-get install graphicsmagick-imagemagick-compat
and then install gem like that
PATH="/usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16:$PATH" gem install rmagick -v '2.13.2'
May be you are installing ImageMagick version 7.x.x which will generate different folder names in your usr/lib/local/include/ImageMagick7.x.x folder.
E.g.
In ImageMagick6.x.x version we have magick, wand named folders, where in ImageMagick7.x.x version have named this MagickCore , MagickWand . So this updation is causing the problem in some gem installation like here. Which is using
magick/some_header.h or wand/some_header.h (Means they are not updated with the new 7.x.x ImageMagick version).That's why we are getting this error :
```
checking for outdated ImageMagick version (<= 6.4.9)... no
checking for presence of MagickWand API (ImageMagick version >= 6.9.0)... no
....
checking for wand/MagickWand.h... no
```
and in log file something like this :
error: 'MagickCore/method-attribute.h' file not found
#include "MagickCore/method-attribute.h"
^
Solution
Install the ImageMagick6.x.x version in your system from the official site : https://www.imagemagick.org/download/ and install it using this commands(after extract zip/tar) :
./configure
make
make install
Then do
gem install rmagick
It will work.
As per the error log it looks like "Magick-config" is missing.
You need to install ImageMagik or GraphicsMagick. These are the commands you should follow which is taken from RMagik Documentation:
1) Go to http://www.imagemagick.org or http://www.graphicsmagick.org and download the latest version of the software to a temporary directory. the extract them :
- tar xvzf ImageMagick.tar.gz
- cd ImageMagick-x.x.x
- ./configure --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8
- make
- sudo make install
- sudo gem install rmagick
Solution for Ubuntu:
sudo apt-get install imagemagick
ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick-config /usr/bin/Magick-config
first run this:
sudo apt-get install imagemagick
then: sudo apt-get install libmagick++-dev
now install rmagick: gem install rmagick
Just run these command
• $ sudo apt-get install imagemagick
• $ sudo apt-get install libmagick++-dev
• $ sudo gem install rmagick
• $ bundle install
I had this same issue when setting up a Rails 6 application in Ubuntu 20.04.
Here's how I solved it
RMagick is an interface between the Ruby programming language and the ImageMagick image processing library. So we first need to install development libraries for ImageMagick:
Step 1:
On Ubuntu, you can run:
sudo apt-get install libmagickwand-dev
On Centos, you can run:
sudo yum install gcc ImageMagick-devel make which
On Arch Linux, you can run:
pacman -Syy pkg-config imagemagick
On Alpine Linux, you can run:
apk add pkgconfig imagemagick imagemagick-dev imagemagick-libs
or you can run if you would like to use ImageMagick 6:
apk add pkgconfig imagemagick6 imagemagick6-dev imagemagick6-libs
On macOS, you can run:
brew install pkg-config imagemagick
or you can run if you would like to use ImageMagick 6:
brew install pkg-config imagemagick#6
On Windows:
Install the latest Ruby+Devkit package which you can get from RubyInstaller for Windows.
You might need to configure PATH environment variable to where the compiler is located.
(Ex: set PATH=C:\Ruby27-x64\msys64\usr\bin;C:\Ruby27-x64\msys64\mingw64\bin;%PATH%)
Download ImageMagick-7.XXXX-Q16-x64-dll.exe (not, ImageMagick-7.XXXX-Q16-x64-static.exe) binary from Windows Binary Release, or you can download ImageMagick 6 from Windows Binary Release.
Install ImageMagick. You need to turn on checkboxes Add application directory to your system path and Install development headers and librarries for C and C++ in an installer for RMagick.
Step 2:
Install the RMagick ruby gem:
gem install rmagick
Step 3:
Now you can add the RMagick ruby gem to your Gemfile:
gem 'rmagick', '~> 4.1'
Note: As of this writing the latest version is 4.1
Step 4:
Finally, you can run bundle install to install the gem to your application.
Resources: rmagick/rmagick GitHub page
That's all.
I hope this helps
Just install ImageMagick-devel package and everything should be fine :)
For Ubuntu Server, I installed it by doing this:
sudo apt-get install imagemagick
sudo apt-get install libmagick++-dev
sudo gem install rmagick -v '2.15.4'
All here wrong for me :(
this helped:
sudo apt-get install libmagickwand-dev
according to rmagick github page
then bundle install went with no errors
If you are using openSUSE, then first check if the ImageMagick installed or not. If it is installed, then do install it development header file.
[arup#sztukajedzenia]$ sudo zypper se imagemagic
root\'s password:
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+-------------------+-------------------------------------------------------+-----------
i | ImageMagick | Viewer and Converter for Images | package
| ImageMagick | Viewer and Converter for Images | srcpackage
| ImageMagick-devel | Include Files and Libraries Mandatory for Development | package
| ImageMagick-doc | Document Files for ImageMagick Library | package
| ImageMagick-extra | Viewer and Converter for Images - extra codecs | package
[arup#sztukajedzenia]$ sudo zypper in ImageMagick-devel
root\'s password:
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 2 NEW packages are going to be installed:
ImageMagick-devel libbz2-devel
........
You need to run both the command for ubuntu
sudo apt-get install libmagick++-dev
sudo apt-get install imagemagick
Then try to install
gem install rmagick
For mac users, install imagemagick 6 since the newest version 7 isn't compatible.
brew install imagemagick#6
gem install rmagick
The above should work after you uninstall what you already have.
For Fedora 27 I resolved this problem:
sudo dnf install ImageMagick-devel ImageMagick
gem install rmagick

ruby 2.0 rails gem install error "cannot load such file -- openssl"

I am using osx 10.8.2 installed ruby 2.0 and....
got this when trying to run "sudo gem install rails"
$ sudo gem install rails
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
I had ruby 1.9.x and rails 3.2.x working alright before
You have to install OpenSSL first and recompile ruby again:
RVM:
rvm pkg install openssl
rvm reinstall ruby-2.0.0-p0 --with-gcc=gcc-4.7 --with-openssl-dir=$rvm_path/usr
If you're using RVM please follow:
$ brew install automake
$ rvm pkg install openssl
$ rvm requirements run
$ rvm reinstall all --force
$ gem install rails
It worked for me.
I had very bad time with this ERROR.
Finally i done with it. There is only Once solution either you are with RVM or without RVM.
Make sure you have installed OpenSSL first BEFORE installing ruby.
RVM
Uninstall rvm
rvm implode
or
rm -rf ~/.rvm
Don’t forget to remove the script calls in your .bashrc and/or .bash_profile (or whatever shell you’re using).
sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev curl git-core python-software-properties libpq-dev nodejs
Then install RVM, post ruby.
OR
rvm pkg install openssl
rvm reinstall ruby-2.0.0-p0 --with-gcc=gcc-4.7 --with-openssl-dir=$rvm_path/usr
WITHOUT RVM
First you should find where Ruby is:
whereis ruby
will list all the places where it exists on your system, then you can remove all them explicitly. Or you can use something like this:
rm -rf /usr/local/lib/ruby
rm -rf /usr/lib/ruby
rm -f /usr/local/bin/ruby
rm -f /usr/bin/ruby
rm -f /usr/local/bin/irb
rm -f /usr/bin/irb
rm -f /usr/local/bin/gem
rm -f /usr/bin/gem
THEN
sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev curl git-core python-software-properties libpq-dev nodejs
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
tar -xvzf ruby-2.0.0-p247.tar.gz
cd ruby-2.0.0-p247/
./configure --prefix=/usr/local
make
make install
I hope this help you.
I fix this error for ruby 2.1.2 as follow.
rvm pkg install openssl
rvm reinstall ruby-2.1.2 --with-openssl-dir=$rvm_path/usr
On OSX, with rbenv and homebrew, the following worked for me:
brew install openssl
CONFIGURE_OPTS=--with-openssl-dir=$(brew --prefix openssl) rbenv install whatever-ruby-version
This worked for me which is similar to some of the other answers already posted.
rvm pkg install openssl
rvm reinstall all --force
When installing ruby 2.0, it is possible that rubygems 2.0 installation did not complete ok, because of openssl.
Make sure you provide a valid path to the openssl config file; you could:
find . -type f -name "openssl.cnf"
path is usually $HOME/.rvm/usr or $HOME/.rvm/usr/ssl
Then
[sudo] rvm reinstall ruby-2.0.0-p0 --with-openssl-dir=[openssl.cnf path] --verify-downloads 1
Make sure rubygems installation complete successfully.
Might be a better way to fix that path without reinstalling, but this should do it.
Make sure to check out this page on the rvm site: https://rvm.io/packages/openssl/
Running
rvm requirements run
gave me:
Missing required packages: autoconf, automake, libtool, pkg-config, apple-gcc42, readline, libxml2, libxslt, libksba, openssl, sqlite
after brew install autoconf automake ...
I was able to rvm reinstall 2.0.0 without openssl errors
I had the same problem with the same OS version. I use rvm and followed the steps in this command:
$ rvm requirements
Following those instructions, I ran:
$ brew update
$ brew tap homebrew/dupes
$ brew install bash curl git
$ brew install autoconf automake apple-gcc42 libtool pkg-config openssl readline libyaml sqlite libxml2 libxslt libksba
I had the same problem earlier, tried all of the snippets about and none of them worked out. After looking around for a bit the following worked for me:
$ rvm remove 2.0.0 # get rid of unsuccessful installation
$ rvm get head --autolibs=3 # get the latest RVM and build required libs
$ rvm requirements # just in case, install all other required stuff
$ rvm install ruby-2.0.0
$ rvm --default use ruby-2.0.0
What does rvm get head --autolibs=3 do exactly? I'm guess it automatically downloads dependencies, but I was hoping for a clear answer.
I encountered the same openssl error on Fedora when trying to use gem install <package>. It seems you need to install additional packages with yum/dnf
sudo dnf install rubygems rubygem-bundler ruby-devel mariadb-devel
After running the above command, gem install <package> should now work.
just went through the same problem. Takes a bit time but, upgrading openssl with
brew upgrade openssl#1.1
worked for me. Version might be different in the future, type brew install openssl to see which version you can upgrade to. I hope it helps.
If you have libssl1.1, your problem may be that these older versions of ruby (2.4 is the cutoff) are only compatible with libssl1.0.
For debian/ubuntu, please ensure that apt-get install libssl1.0-dev succeeds.
If you are using ruby-install, it will take the same openssl argument as rvm:
ruby-install ruby-2.0.0-p247 -- --with-openssl-dir=/usr/local/opt/openssl

Rails ImageMagic and rmagic

I am following the tutorial http://railscasts.com/episodes/253-carrierwave-file-uploads?view=comments by ryan but he state that we must install imagemagic. so what i have done to install it his has follow
gem "carrierwave"
gem "mini_magick"
gem "rmagick"
in the gemfile. But this still fails when i do bundle. What would be the best way to install it. I am using linux ubuntu and fairly new to it.
You need to install imagemagick on ubuntu then install the rmagick gem.
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
run on linux -
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
sudo gem install rmagick

Not able to run gem command and build ruby with zlib support

I didn't know that installing ruby is such a pain
After lot of trouble with curl certificate, I installed the rvm using the methods mentioned in the rvm site also with lot of help from stackoverflow questions.
Now I am trying to install rails using the gems command
gem install rails
but I always get this error
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand
I did follow every thing mentioned here https://rvm.beginrescueend.com/packages/zlib/
and also as a mentioned in a stackoverflow post
I did install all the tools as required by the requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel
But still I get this error. When I looked at the build log for ruby under
/usr/local/rvm/log/ruby-1.9.3-p125/configure.log
I see this error
[2012-04-07 01:13:44] ./configure --prefix=/usr/local/rvm/rubies/ruby-1.9.3-p125 --enable-shared --disable-install-doc --with-zlib --with-opt-dir=/usr/local/rvm/usr --with-libyaml
configure: WARNING: unrecognized options: --with-zlib, --with-libyaml
Is the rvm broken ? or is there a problem while building the ruby src.
Note: I am running fedora 14
RVM causes more problems than it solves (IMHO). Better tools are ruby-build and rb-env. Newer tools that look very good too are ruby-install and chruby.
Here are my notes from my recent Red Hat Enterprise Linux (RHEL) installation of Ruby, which I believe is pretty similar to Fedora. Perhaps these notes can be of some help to you. Ask me questions if you like.
Install zlib
yum install zlib zlib-devel
Install YAML
export k=yaml v=0.1.4
wget http://pyyaml.org/download/libyaml/$k-$v.tar.gz
tar zxvf $k-$v.tar.gz
cd $k-$v
./configure
make && make install
Install X11 if you want X or headless browsing for testing
yum install
xorg-x11-fonts-misc
xorg-x11-fonts-truetype
xorg-x11-server-Xorg
xorg-x11-server-Xvfb
Install libraries
yum install
gdbm gdbm-devel
ncurses ncurses-devel
openssl openssl-devel
readline readline-devel
tk tk-devel
libjpeg libjpeg-devel
libpng libpng-devel
libxml2 libxml2-devel
libxslt libxslt-devel
zlib zlib-devel
Install ruby-build
cd /opt
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build/
./install.sh
Install Ruby
export k=ruby v=1.9.3-p125
wget http://ftp.ruby-lang.org/pub/ruby/1.9/$k-$v.tar.gz
tar zxvf $k-$v.tar.gz
cd $k-$v
# Either onfigure with defaults...
./configure
# Or configure with custom locations...
./configure --prefix=/opt/$k/$v --enable-shared --with-opt-dir=/opt/yaml/current
make && make check && make install
Environment
Edit /etc/environment to add this:
RUBYOPT='-r rubygems -r psych'
If you put Ruby in a custom directory, also merge this with your existing path:
PATH=/opt/ruby/1.9.3-p125/bin (or wherever you put it)
Load environment:
source /etc/environment
Verify gem runs and you see the intial set of gems:
gem list
Gem update:
gem update --system

ImageMagick / RMagick - Can't install RMagick 2.13.1. Can't find Magick-config

I used a script to install ImageMagick http://github.com/masterkain/ImageMagick-sl
After a while, I got ImageMagick installed.
Then I ran sudo gem install rmagick and got
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in...
I'm working in OSX Snow Leopard with Ruby 1.9.2 and Rails 3. Any ideas?
I was getting the same error and it got resolved after installing the libmagick9-dev library on ubuntu 11.
Update (Thanks to the commenters - Dec. 2012)
$ sudo apt-get install libmagickwand-dev or $ sudo apt-get install graphicsmagick-libmagick-dev-compat for ubuntu 12
$ sudo apt-get install libmagickwand-dev or $ sudo apt-get install libmagick9-dev for ubuntu 11 or below.
$ yum install ImageMagick-devel for centos
$ brew install imagemagick for Mac OS (using Homebrew)
you need the imagemagick libraries under ubuntu
$ sudo apt-get install libmagickwand-dev
it contains all missing libraires
then run bundle install command
I believe you need the Imagemagick libraries.
If you are using Homebrew (which I'd highly recommend), simply do
$ brew install imagemagick
Then rerun bundle install
Mac OS Mountain Loin (using Homebrew)
download and install http://xquartz.macosforge.org/trac/wiki/X112.7.2
brew install imagemagick
gem install rmagick
sudo apt-get install libmagickwand-dev
works well for Ubuntu 12.10
This is assuming you have installed all other dependencies viz.
sudo apt-get install imagemagick ruby ruby-dev gem`
On CentOS 5.7, I got it to work by first specifying PKG_CONFIG_PATH:
export PKG_CONFIG_PATH=/usr/local/src/ImageMagick-6.7.5-10/magick/
gem install rmagick
For those who got
InitializeMagick() in -lMagickCore... no; -lMagick... no; -lMagick++... no;
this worked for me in OS X 10.8: https://github.com/maddox/magick-installer
From here: RVM + Ruby 1.9.2 + Rmagick + Lion = System Works, RVM Doesn't
Initially, I came around to installing rmagick because it seemed to be a dependency when I tried installing libgtk2.0-dev. I was trying to install that package, because the RGtk2.0 is a requirement for using R package called rattle.
Anyway, none of the above solutions worked for me in installing in my Ubuntu 12.04. Even running sudo apt-get update first didn't seem to help, nor this related posting: Installing rmagick on Ubuntu
I eventually found what works is to troubleshoot using sudo aptitude rather than apt-get.
https://askubuntu.com/questions/223237/unable-to-correct-problems-you-have-held-broken-packages
I recommend the technique of using aptitude to work through the package installation issue.
On Mac Os X, check if /opt/local/bin is in your PATH. If not:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
sudo gem install rmagick
This worked for me!
I had an issue installing Rmagick gem version 2.13.2 on Debian Jessie. After fighting with the packages in the other answers, I upgraded the version of the Rmagick gem from 2.13.2 to the latest (2.16.0 at time of writing). This installed successfully.
bundle update rmagick
If you tried all solutions, of all posts of whole Internet, have installed and reinstalled many times all indicated packages in all Linux or Mac distributions/versions (even in Windows) and it still not working, close your terminal and open it again. Some times, even if your reload all shell environment, only after I reopen the terminal the bundle install was successfully completed.
After several days of searching, my problema was related to some missing libraries, and the one that get the gem installed was this one:
brew install pkg-config
after this I did my bundle install again and it worked.

Resources