简体   繁体   中英

gem install pg failed

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

I tried different commands to fix it. These commands are not working.

sudo apt-get install ruby-dev build-essential
sudo apt-get install postgresql-client libpq5 libpq-dev

It says

/home/user/.rvm/gems/ruby-2.6.6/extensions/x86_64-linux/2.6.0/pg-1.2.3/mkmf.log

Inside mkmg.log file

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

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

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

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

"gcc -E -I/usr/share/rvm/rubies/ruby-2.6.6/include/ruby-2.6.0/x86_64-linux -I/usr/share/rvm/rubies/ruby-2.6.6/include/ruby-2.6.0/ruby/backward -I/usr/share/rvm/rubies/ruby-2.6.6/include/ruby-2.6.0 -I. -I/usr/include/postgresql.........."
conftest.c:3:10: fatal error: libpq-fe.h: No such file or directory
    3 | #include <libpq-fe.h>
      |          ^~~~~~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
/* end */

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


So how can I fix this. Is there a solution in mkmf.log file.

You should run following command locate that file

locate libpq-fe.h

if locate command not working you can install apt-get install locate and updatedb and search. If you found compare with the location. Of you can check above locations and see if file is present, if in other place then you can make link of following using following commands. Please use directories as per your system

sudo ln -s /usr/include/postgresql/libpq-fe.h /usr/include/
sudo ln -s /usr/include/postgresql/postgres_ext.h /usr/include/ 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM