I tried to create rails app by
rails new app-name --database=postgresql
This threw error for few gems like
An error occurred while installing pg
This was for few gems like racc, byebug. Even though I have all the pre-requisistes:
ruby -v
#ruby 3.0.0
rails -v
# rails 6.1.4.1
and could log into postgres by giving
sudo -i -u postgres
I tried bundle install but the same issue persisted. So I decided to manually install every gem and started with pg gem.
When I run sudo gem install pg it gave
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.7.0/gems/pg-1.2.3/ext
/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf*****hp.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/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.
I tried
sudo apt-file search libpq-fe.h
and got /usr/include/postgresql/libpq-fe.h but actually I don't have /usr/include/postgresql.
I tried few other commands like
sudo apt-get install postgresql libpq-dev
sudo apt-get install libpq-dev
They didn't throw any error but still sudo gem install pg was not working.
I tried all others solutions i could find on internet, so I'm not sure whether I have broken package or installed anything wrong or what went wrong. Thanks in advance for helping.