tl;dr
apt-get でのインストールに失敗して困ったらとりあえず sudo apt-get update してみよう
はまったこと
Cloud9 (旧Cloud9。AWS Cloud9ではない) 環境を利用して RailsTutorial (Rails5.1 (第4版) を進めています。
13章でポストした画像をリサイズするために ImageMagick をインストールする必要があるのですが、
チュートリアルの手順には以下のように記載がありました。
$ sudo yum install -y ImageMagick
が、Cloud9 は Debian系の Ubuntu のため パッケージ管理は yum (RHEL系) ではなく apt-get を使用します。
ですので、以下のコマンドに読み替えて実行しました。
sudo apt-get install imagemagick
が結果は以下の通りエラー。
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package imagemagick is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'imagemagick' has no installation candidate
解決策
以下コマンドで、一度アップデートすれば解決しました。
$ sudo apt-get update
その後改めてインストール
$ sudo apt-get install imagemagick
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libdjvulibre-text libdjvulibre21 libilmbase6 libmagickcore5-extra
libnetpbm10 libopenexr6 libwmf0.2-7 netpbm
Suggested packages:
imagemagick-doc autotrace cups-bsd lpr lprng enscript ffmpeg gimp gnuplot
grads hp2xx html2ps libwmf-bin mplayer povray radiance sane-utils
texlive-base-bin transfig xdg-utils ufraw-batch libwmf0.2-7-gtk
The following NEW packages will be installed:
imagemagick libdjvulibre-text libdjvulibre21 libilmbase6
libmagickcore5-extra libnetpbm10 libopenexr6 libwmf0.2-7 netpbm
0 upgraded, 9 newly installed, 0 to remove and 267 not upgraded.
Need to get 2621 kB of archives.
After this operation, 8859 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libdjvulibre-text all 3.5.25.4-3 [48.8 kB]
Get:2 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libdjvulibre21 amd64 3.5.25.4-3 [553 kB]
Get:3 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libilmbase6 amd64 1.0.1-6ubuntu1 [53.6 kB]
Get:4 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libopenexr6 amd64 1.6.1-7ubuntu1 [164 kB]
Get:5 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libwmf0.2-7 amd64 0.2.8.4-10.3ubuntu1.14.04.1 [143 kB]
Get:6 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libmagickcore5-extra amd64 8:6.7.7.10-6ubuntu3.13 [58.4 kB]
Get:7 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main imagemagick amd64 8:6.7.7.10-6ubuntu3.13 [189 kB]
Get:8 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libnetpbm10 amd64 2:10.0-15ubuntu2 [69.0 kB]
Get:9 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main netpbm amd64 2:10.0-15ubuntu2 [1341 kB]
Fetched 2621 kB in 5s (506 kB/s)
Selecting previously unselected package libdjvulibre-text.
(Reading database ... 72975 files and directories currently installed.)
Preparing to unpack .../libdjvulibre-text_3.5.25.4-3_all.deb ...
Unpacking libdjvulibre-text (3.5.25.4-3) ...
Selecting previously unselected package libdjvulibre21:amd64.
Preparing to unpack .../libdjvulibre21_3.5.25.4-3_amd64.deb ...
Unpacking libdjvulibre21:amd64 (3.5.25.4-3) ...
Selecting previously unselected package libilmbase6:amd64.
Preparing to unpack .../libilmbase6_1.0.1-6ubuntu1_amd64.deb ...
Unpacking libilmbase6:amd64 (1.0.1-6ubuntu1) ...
Selecting previously unselected package libopenexr6:amd64.
Preparing to unpack .../libopenexr6_1.6.1-7ubuntu1_amd64.deb ...
Unpacking libopenexr6:amd64 (1.6.1-7ubuntu1) ...
Selecting previously unselected package libwmf0.2-7:amd64.
Preparing to unpack .../libwmf0.2-7_0.2.8.4-10.3ubuntu1.14.04.1_amd64.deb ...
Unpacking libwmf0.2-7:amd64 (0.2.8.4-10.3ubuntu1.14.04.1) ...
Selecting previously unselected package libmagickcore5-extra:amd64.
Preparing to unpack .../libmagickcore5-extra_8%3a6.7.7.10-6ubuntu3.13_amd64.deb ...
Unpacking libmagickcore5-extra:amd64 (8:6.7.7.10-6ubuntu3.13) ...
Selecting previously unselected package imagemagick.
Preparing to unpack .../imagemagick_8%3a6.7.7.10-6ubuntu3.13_amd64.deb ...
Unpacking imagemagick (8:6.7.7.10-6ubuntu3.13) ...
Selecting previously unselected package libnetpbm10.
Preparing to unpack .../libnetpbm10_2%3a10.0-15ubuntu2_amd64.deb ...
Unpacking libnetpbm10 (2:10.0-15ubuntu2) ...
Selecting previously unselected package netpbm.
Preparing to unpack .../netpbm_2%3a10.0-15ubuntu2_amd64.deb ...
Unpacking netpbm (2:10.0-15ubuntu2) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up libdjvulibre-text (3.5.25.4-3) ...
Setting up libdjvulibre21:amd64 (3.5.25.4-3) ...
Setting up libilmbase6:amd64 (1.0.1-6ubuntu1) ...
Setting up libopenexr6:amd64 (1.6.1-7ubuntu1) ...
Setting up libwmf0.2-7:amd64 (0.2.8.4-10.3ubuntu1.14.04.1) ...
Setting up libmagickcore5-extra:amd64 (8:6.7.7.10-6ubuntu3.13) ...
Setting up imagemagick (8:6.7.7.10-6ubuntu3.13) ...
update-alternatives: using /usr/bin/compare.im6 to provide /usr/bin/compare (compare) in auto mode
update-alternatives: using /usr/bin/animate.im6 to provide /usr/bin/animate (animate) in auto mode
update-alternatives: using /usr/bin/convert.im6 to provide /usr/bin/convert (convert) in auto mode
update-alternatives: using /usr/bin/composite.im6 to provide /usr/bin/composite (composite) in auto mode
update-alternatives: using /usr/bin/conjure.im6 to provide /usr/bin/conjure (conjure) in auto mode
update-alternatives: using /usr/bin/import.im6 to provide /usr/bin/import (import) in auto mode
update-alternatives: using /usr/bin/identify.im6 to provide /usr/bin/identify (identify) in auto mode
update-alternatives: using /usr/bin/stream.im6 to provide /usr/bin/stream (stream) in auto mode
update-alternatives: using /usr/bin/display.im6 to provide /usr/bin/display (display) in auto mode
update-alternatives: using /usr/bin/montage.im6 to provide /usr/bin/montage (montage) in auto mode
update-alternatives: using /usr/bin/mogrify.im6 to provide /usr/bin/mogrify (mogrify) in auto mode
Setting up libnetpbm10 (2:10.0-15ubuntu2) ...
Setting up netpbm (2:10.0-15ubuntu2) ...
Processing triggers for libc-bin (2.19-0ubuntu6.11) ...
インストール成功!(Completed とか出てませんが成功してます)
おわりに
Rails Tutorial は開発環境など含め丁寧に解説されているため、手順に沿って進めればまず問題は起こらないと思います。
が、今回 Rails Tutorial の推奨開発環境は AWS Cloud9 だったのですが、旧Cloud9 のアカウントを持っており、新たにAWS Cloud9 の環境を作り直すのが面倒だったため旧Cloud9 の環境を利用しました。
Ubuntu(Debian系)環境に慣れている方であれば問題なく解決できるケースかと思いますが、(私含め)チュートリアルを進めている初学者であればちょっとエラーが出るとすぐはまってしまうことも多々あると思います。
それはそれでよい経験ではあるのですが、RailsTutorial を通じて Rails を学ぶという目的からは外れてしまいますので、環境等の知識がない方は素直に推奨環境に従うことをオススメします。