ツヨシのブログ

技術的な事とか日常の事とか徒然なるままに

スポンサーリンク

postgresqlをインストールした時の忘備録

スポンサーリンク

postgresqlをインストールした時の忘備録

忘備録の概要

railspostgresqlを使用したいと思い、gemを使ってインストールした。

環境

環境としてvagrantを使用した。

$ rails -v
Rails 4.1.6
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
$ uname -r
3.13.0-36-generic
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

インストール

gemでpostgresqlインストール。

$ sudo gem install pg -v '0.17.1'

エラーとなる。。。

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:2:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/pg-0.17.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/pg-0.17.1/ext/gem_make.out

対応

ruby-devをインストール

どうやら、ruby-devが必要のようだ。以下を参照にruby-devをインストールした。

[Ubuntu] ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb | Chris J. Lee

$ sudo apt-get install ruby-dev

ruby-devインストールログだよ。

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontenc1 libgl1-mesa-dri
  libgl1-mesa-glx libglapi-mesa libice6 libllvm3.4 libpciaccess0 libpixman-1-0
  libsm6 libtxc-dxtn-s2tc0 libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0
  libxcb-glx0 libxcb-present0 libxcb-sync1 libxcomposite1 libxdamage1
  libxfixes3 libxfont1 libxkbfile1 libxmu6 libxpm4 libxrandr2 libxrender1
  libxshmfence1 libxt6 libxxf86vm1 x11-common x11-xkb-utils xfonts-base
  xfonts-encodings xfonts-utils xserver-common xserver-xorg-core
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  ruby1.9.1-dev
The following NEW packages will be installed:
  ruby-dev ruby1.9.1-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 877 kB of archives.
After this operation, 4,228 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main ruby1.9.1-dev amd64 1.9.3.484-2ubuntu1 [872 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/main ruby-dev all 1:1.9.3.4 [4,660 B]
Fetched 877 kB in 11s (74.8 kB/s)
Selecting previously unselected package ruby1.9.1-dev.
(Reading database ... 67941 files and directories currently installed.)
Preparing to unpack .../ruby1.9.1-dev_1.9.3.484-2ubuntu1_amd64.deb ...
Unpacking ruby1.9.1-dev (1.9.3.484-2ubuntu1) ...
Selecting previously unselected package ruby-dev.
Preparing to unpack .../ruby-dev_1%3a1.9.3.4_all.deb ...
Unpacking ruby-dev (1:1.9.3.4) ...
Setting up ruby1.9.1-dev (1.9.3.484-2ubuntu1) ...
Setting up ruby-dev (1:1.9.3.4) ...

再度インストール

再度インストールして成功!!

$ sudo gem install pg -v '0.17.1'
Building native extensions.  This could take a while...
Successfully installed pg-0.17.1
1 gem installed
Installing ri documentation for pg-0.17.1...
Installing RDoc documentation for pg-0.17.1...
vagrant@vagrant-ubuntu-trusty-64:~$
vagrant@vagrant-ubuntu-trusty-64:~$