ruby-on-rails 无法在ruby on rails中安装pg gem

eqfvzcg8  于 2023-05-19  发布在  Ruby
关注(0)|答案(3)|浏览(177)

我正在尝试安装'pg' gem,并得到以下错误:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/thomas/.rvm/gems/ruby-2.7.1/gems/pg-1.2.3/ext
/usr/share/rvm/rubies/ruby-2.7.1/bin/ruby -I
/usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0 -r
./siteconf20200423-27933-r303r1.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/share/rvm/rubies/ruby-2.7.1/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/thomas/.rvm/gems/ruby-2.7.1/extensions/x86_64-linux/2.7.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

许多SO搜索表明

sudo apt-get install libpq-dev

但这给了

Err:1 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 libpq5 amd64 11.4-1.pgdg16.04+1
  404  Not Found [IP: 87.238.57.227 80]
Err:2 http://apt.postgresql.org/pub/repos/apt xenial-pgdg/main amd64 libpq-dev amd64 11.4-1.pgdg16.04+1
  404  Not Found [IP: 87.238.57.227 80]
E: Failed to fetch http://apt.postgresql.org/pub/repos/apt/pool/main/p/postgresql-11/libpq5_11.4-1.pgdg16.04+1_amd64.deb  404  Not Found [IP: 87.238.57.227 80]

E: Failed to fetch http://apt.postgresql.org/pub/repos/apt/pool/main/p/postgresql-11/libpq-dev_11.4-1.pgdg16.04+1_amd64.deb  404  Not Found [IP: 87.238.57.227 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

运行建议的
apt-get update --fix-missing
给出与上面相同的错误。有什么想法吗?我看过很多有同样问题的帖子,通常提供类似的解决方案,但他们似乎在这里不起作用。先谢谢你了

vwhgwdsa

vwhgwdsa1#

sudo apt-get install libpq-dev
41zrol4v

41zrol4v2#

我尝试了许多解决方案,但从official site安装Postgres对我来说是有效的。

fcg9iug3

fcg9iug33#

如果你用brew安装libpq和postgres,我的解决方案是:

  • 获取pgconfig的路径,我的是:/opt/homebrew/Cellar/libpq/15.2/bin/pg_config
  • 运行gem install pg -- --with-pg-config=/opt/homebrew/Cellar/libpq/15.2/bin/pg_config

终于成功了。

相关问题