Skip to content

Instantly share code, notes, and snippets.

@rgiaviti
Last active September 30, 2016 18:31
Show Gist options
  • Select an option

  • Save rgiaviti/c41a53e3cac65d50ea908df9edb2508e to your computer and use it in GitHub Desktop.

Select an option

Save rgiaviti/c41a53e3cac65d50ea908df9edb2508e to your computer and use it in GitHub Desktop.
Fixing error when installing PostgreSQL gem in Ubuntu 15.10
# The MIT License (MIT)
#
# Copyright (c) 2016 Ricardo Giaviti
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# We try to install the PostgreSQL gem in Ubuntu 15.10 (PostgreSQL are running in a docker conatiner),
# but something bad happens
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/rgiaviti/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/ext
/home/rgiaviti/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160419-11751-1mpjarv.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/rgiaviti/.rvm/rubies/ruby-2.3.0/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/rgiaviti/.rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/pg-0.18.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/rgiaviti/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /home/rgiaviti/.rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/pg-0.18.4/gem_make.out
# So, we need a specific package to install this gem and build the native extensions
$ sudo apt-get install libpq-dev
# And, we try again:
$ gem install pg
# Finally, we are good to create a new rails app with postgresql
$ rails new myapp --database=postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment