Raspberry Pi (Arch Linux)にgemでmechanizeをインストールする時のエラー対処

install gcc

Raspberry PiのOSに使っているArch LinuxのRuby環境構築の続き。gemでmechanizeをインストールしようとしてハマったのでその時の対処方法についての備忘録。やはり環境から構築する作業は慣れない作業でかなりストレス。。。

gemでmechanizeをインストールしようとした時のエラーがこのとおり。

[root@alarmpi tools]# gem install mechanize –no-user-install
Fetching: net-http-digest_auth-1.2.1.gem (100%)
Fetching: net-http-persistent-2.8.gem (100%)
Fetching: mime-types-1.21.gem (100%)
Fetching: nokogiri-1.5.6.gem (100%)
Building native extensions. This could take a while…
ERROR: Error installing mechanize:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for libxml/parser.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.

調べるとlibxml2、libxsltのライブラリと、ビルドするためにgccのインストールが必要ということが判明。Linuxもいろいろ、Rubyもいろいろあって、ここまでたどり着くまで結構大変だった。

[root@alarmpi tools]# pacman -S libxml2
resolving dependencies…
looking for inter-conflicts…

Targets (1): libxml2-2.8.0-1

Total Download Size: 1.29 MiB
Total Installed Size: 10.64 MiB

Proceed with installation? [Y/n] Y
:: Retrieving packages from extra…
libxml2-2.8.0-1-armv6h 1321.7 KiB 238K/s 00:06 [######################] 100%
(1/1) checking package integrity [######################] 100%
(1/1) loading package files [######################] 100%
(1/1) checking for file conflicts [######################] 100%
(1/1) checking available disk space [######################] 100%
(1/1) installing libxml2 [######################] 100%

[root@alarmpi ~]# pacman -S libxslt
resolving dependencies…
looking for inter-conflicts…

Targets (1): libxslt-1.1.26-3

Total Download Size: 0.37 MiB
Total Installed Size: 2.93 MiB

Proceed with installation? [Y/n] Y
:: Retrieving packages from extra…
libxslt-1.1.26-3-armv6h 377.0 KiB 106K/s 00:04
(1/1) checking package integrity
(1/1) loading package files
(1/1) checking for file conflicts
(1/1) checking available disk space
(1/1) installing libxslt

gccはpacman -S base-develからでもインストールできるはずだがなぜかエラー。。。pacman -S gccで直接指定すると無事にインストールできた。

[root@alarmpi ~]# pacman -S gcc
resolving dependencies…
looking for inter-conflicts…

Targets (7): cloog-0.18.0-1 gcc-libs-4.7.2-4
isl-0.11.1-1 libmpc-1.0.1-1
mpfr-3.1.1.p2-2 ppl-1.0-1 gcc-4.7.2-4

Total Download Size: 15.08 MiB
Total Installed Size: 87.50 MiB
Net Upgrade Size: 85.51 MiB

Proceed with installation? [Y/n] Y
:: Retrieving packages from core…
gcc-libs-4.7.2-4-armv6h 513.4 KiB 116K/s 00:04
gcc-4.7.2-4-armv6h 14.6 MiB 167K/s 01:30
(7/7) checking package integrity
(7/7) loading package files
(7/7) checking for file conflicts
(7/7) checking available disk space
(1/7) upgrading gcc-libs
(2/7) installing mpfr
(3/7) installing libmpc
(4/7) installing isl
(5/7) installing cloog
(6/7) installing ppl
(7/7) installing gcc

あらためて、gemでmechanizeのインストールを実行で無事完了できました。

[root@alarmpi tools]# gem install mechanize –no-user-install
Building native extensions. This could take a while…
Fetching: ntlm-http-0.1.1.gem (100%)
Fetching: webrobots-0.1.0.gem (100%)
Fetching: unf_ext-0.0.6.gem (100%)
Building native extensions. This could take a while…
Fetching: unf-0.0.5.gem (100%)
Fetching: domain_name-0.5.7.gem (100%)
Fetching: mechanize-2.5.1.gem (100%)
Successfully installed nokogiri-1.5.6
Successfully installed ntlm-http-0.1.1
Successfully installed webrobots-0.1.0
Successfully installed unf_ext-0.0.6
Successfully installed unf-0.0.5
Successfully installed domain_name-0.5.7
Successfully installed mechanize-2.5.1
7 gems installed

gem listを実行してみた。

*** LOCAL GEMS ***

bigdecimal (1.1.0)
domain_name (0.5.7)
io-console (0.3)
json (1.5.4)
mechanize (2.5.1)
mime-types (1.21)
minitest (2.5.1)
net-http-digest_auth (1.2.1)
net-http-persistent (2.8)
nokogiri (1.5.6)
ntlm-http (0.1.1)
oauth (0.4.7)
rake (0.9.2.2)
rdoc (3.9.5)
ruby-hmac (0.4.0)
rubygems-update (1.8.25)
unf (0.0.5)
unf_ext (0.0.6)
webrobots (0.1.0)