18
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Tips】Ubuntuへのpg gemインストール時に発生しうるエラーへの対処

Posted at

問題:pg gem インストールの失敗

入力

gem install pg -v '0.18.4'

出力

ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

    current directory: /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/pg-0.18.4/ext
/home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/bin/ruby -r ./siteconf20190314-768-1y18wv0.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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=/home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib

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

  /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-0.18.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/pg-0.18.4 for inspection.
Results logged to /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-0.18.4/gem_make.out

環境

  • Windows Subsystem for Linux (WSL)
    • Ubuntu 18.04 LTS
  • anyenv
    • rbenv 1.1.1-39-g59785f6
      • ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]

原因:PostgreSQLライブラリ

native extensionとして必要なPostgreSQLに関連するライブラリがインストールされていない。

解決方法

sudo apt install libpq-dev
gem install pg -v '0.18.4'

補足

libpg-devではなくlibpq-dev(gではなくq)であることに注意。
どちらもPostgreSQLの略称であると思われるが、gemにおいてはpg、aptでインストールするパッケージにおいてはpqと略しているため注意が必要。前者は PostgreSQL Gem の略称の可能性もあるが。

参考文献

18
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?