skip to Main Content

I have been getting this error while installing my rails project with rails new Project --database=postgresql
When I try to install the bundle, these errors pop up:

Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies.....
Using rake 13.0.6
Using concurrent-ruby 1.1.10
Using racc 1.6.0
Using crass 1.0.6
Using rack 2.2.4
Using minitest 5.16.2
Using builder 3.2.4
Using marcel 1.0.2
Using websocket-extensions 0.1.5
Using digest 3.1.0
Using nio4r 2.5.8
Using mini_mime 1.1.2
Using erubi 1.11.0
Using bindex 0.8.1
Using timeout 0.3.0
Using bundler 2.3.17
Using matrix 0.4.2
Using msgpack 1.5.4
Using public_suffix 4.0.7
Using io-console 0.5.11
Using strscan 3.0.4
Using method_source 1.0.0
Using zeitwerk 2.6.0
Using childprocess 4.1.0
Using rexml 3.2.5
Using thor 1.2.1
Using rubyzip 2.3.2
Using websocket 1.2.9
Using i18n 1.12.0
Using tzinfo 2.0.5
Using nokogiri 1.13.8 (x86_64-linux)
Using rack-test 2.0.2
Using sprockets 4.1.1
Using websocket-driver 0.7.5
Using puma 5.6.4
Using mail 2.7.1
Using net-protocol 0.1.3
Using bootsnap 1.13.0
Using addressable 2.8.0
Using reline 0.3.1
Using regexp_parser 2.5.0
Using activesupport 7.0.3.1
Using loofah 2.18.0
Using net-smtp 0.3.1
Using xpath 3.2.0
Using irb 1.4.1
Using net-imap 0.2.3
Using selenium-webdriver 4.4.0
Using rails-dom-testing 2.0.3
Using activemodel 7.0.3.1
Using rails-html-sanitizer 1.4.3
Using capybara 3.37.1
Using net-pop 0.1.1
Using globalid 1.0.0
Using activerecord 7.0.3.1
Using actionview 7.0.3.1
Using debug 1.6.2
Using actionpack 7.0.3.1
Using webdrivers 5.0.0
Using jbuilder 2.11.5
Using activejob 7.0.3.1
Using actioncable 7.0.3.1
Using activestorage 7.0.3.1
Using railties 7.0.3.1
Using actionmailbox 7.0.3.1
Using actiontext 7.0.3.1
Using actionmailer 7.0.3.1
Using importmap-rails 1.1.5
Using stimulus-rails 1.1.0
Using turbo-rails 1.1.1
Using web-console 4.2.0
Using sprockets-rails 3.4.2
Using rails 7.0.3.1

Installing pg 1.4.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.3/ext
/home/christian/.rbenv/versions/3.1.2/bin/ruby -I
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0 -r
./siteconf20220811-57965-mz3s1i.rb extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... yes
Using config values from /usr/bin/pg_config
Using libpq from /usr/lib/x86_64-linux-gnu
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*****************************************************************************

Unable to find PostgreSQL client library.

Please install libpq or postgresql client package like so:
  sudo apt install libpq-dev
  sudo yum install postgresql-devel
  sudo zypper in postgresql-devel
  sudo pacman -S postgresql-libs

or try again with:
  gem install pg -- --with-pg-config=/path/to/pg_config

or set library paths manually with:
gem install pg -- --with-pg-include=/path/to/libpq-fe.h/
--with-pg-lib=/path/to/libpq.so/

*** 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/christian/.rbenv/versions/3.1.2/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-gvl-unlock
    --disable-gvl-unlock
    --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/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/pg-1.4.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.3 for
inspection.
Results logged to
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/pg-1.4.3/gem_make.out

/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:95:in
`run'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:47:in
`block in build'
  /home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tempfile.rb:317:in `open'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:26:in
`build'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:161:in
`build_extension'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:195:in
`block in build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in
`each'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in
`build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/installer.rb:853:in
`build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/rubygems_gem_installer.rb:71:in
`build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/source/rubygems.rb:209:in
`install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/gem_installer.rb:54:in
`install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/parallel_installer.rb:186:in
`do_install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/parallel_installer.rb:177:in
`block in worker_pool'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:62:in
`apply_func'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:57:in
`block in process_queue'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:54:in
`loop'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:54:in
`process_queue'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:91:in
`block (2 levels) in create_threads'

An error occurred while installing pg (1.4.3), and Bundler cannot
continue

.

In Gemfile:
  pg

And on top of that, the repo of the project is created but without an Gemfile.lock
And I have PostgreSQL installed on my computer.
I’m using Ubutu 22.04.1
I have tried a lot of suggestions but still can’t find a way out.
I will really appreciate if somebody could help.

2

Answers


  1. Run the below commands

    gem install pg -v '1.4.3'
    sudo apt-get update
    sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev postgresql-client-common postgresql-client libpq-dev
    
    Login or Signup to reply.
  2. Here’s how I fixed this in my computer.

    First try to install libpq-dev
    sudo apt-get install libpq-dev

    Then the computer would complain about incompatible libpq5 version:

    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:
    
    The following packages have unmet dependencies:
     libpq-dev : Depends: libpq5 (= 14.5-0ubuntu0.22.04.1) but 14.5-1.pgdg20.04+1 is to be installed
    E: Unable to correct problems, you have held broken packages.
    

    This means you have newer version of libpq than the one asked by libpq5-dev. Install the correct libpq5 version:

    sudo apt-get install libpq5=14.5-0ubuntu0.22.04.1

    Then try to install libpq-dev again

    sudo apt-get install libpq-dev

    You should be able to do bundle install now

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search