Gitlab install fails... (Could not find gem 'pg')

I’m using Ubuntu 16.10 and was trying to update my Gitlab everything went wrong. Now I have removed/purged it and is trying to install a new version but ran into a problem with Ruby on Rails gems.

Just using:

$ sudo apt install gitlab

Could not find gem ‘pg (~> 0.18.2)’ in any of the gem sources listed in your Gemfile.
I have tried to install pg manually:

$ sudo gem install pg
Successfully installed pg-0.20.0

And even though it reports a sucessfull install, it still gives the same error whenever I’m running

$ sudo apt upgrade
Verifying we have all required libraries…
Could not find gem ‘pg (~> 0.18.2)’ in any of the gem sources listed in your
Gemfile.
dpkg: error processing package gitlab (–configure):
subprocess installed post-installation script returned error exit status 7
Processing triggers for libc-bin (2.24-3ubuntu2) …
Processing triggers for systemd (231-9ubuntu3) …
Processing triggers for ureadahead (0.100.0-19) …
Errors were encountered while processing:
gitlab

  1. Where should I look to figure this out?
  2. How can I prevent Gitlab from installing Prostgresql and use MariaDB instead - if that i a solution?

Yeah I had the same problem

installed libpg dev
sudo apt install libpg-dev

sorted it for me

I already tried this without any luck…

Debian, Last version:

root@meme:

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

    current directory: /var/lib/gems/2.5.0/gems/pg-1.0.0/ext
/usr/bin/ruby2.5 -r ./siteconf20180427-13969-1olpubu.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
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=/usr/bin/$(RUBY_BASE_NAME)2.5
	--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:

  /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/pg-1.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/pg-1.0.0 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/pg-1.0.0/gem_make.out
Gems updated: pg

root@meme: cat /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/pg-1.0.0/mkmf.log

find_executable: checking for pg_config... -------------------- yes

--------------------

"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.5.0 -I/usr/include/ruby-2.5.0/ruby/backward -I/usr/include/ruby-2.5.0 -$
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.5.0 -I/usr/include/ruby-2.5.0/ruby/backward -I/usr/include/ruby-2.5.0 -$
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

find_header: checking for libpq-fe.h... -------------------- no

"gcc -E -I/usr/include/x86_64-linux-gnu/ruby-2.5.0 -I/usr/include/ruby-2.5.0/ruby/backward -I/usr/include/ruby-2.5.0 -I. -Wdate$
conftest.c:3:10: fatal error: libpq-fe.h: No such file or directory
 #include <libpq-fe.h>
          ^~~~~~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
/* end */
--------------------

I got same error in Debian distro [last version].

root@kali:/usr/src/haserl-0.9.35# gem install pg
Building native extensions. This could take a while...
Successfully installed pg-1.0.0
Parsing documentation for pg-1.0.0
Installing ri documentation for pg-1.0.0
Done installing documentation for pg after 1 seconds
1 gem installed
Setting up gitlab (8.13.11+dfsg1-8+deb9u3) ...
Creating/updating gitlab user account...
Making gitlab owner of /var/lib/gitlab...
Could not find gem 'pg (~> 0.18.2)' in any of the gem sources listed in your Gemfile.
dpkg: error processing package gitlab (--configure):
 installed gitlab package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 gitlab