【问题标题】:ERROR: Failed to build gem native extension错误:无法构建 gem 原生扩展
【发布时间】:2016-07-29 17:11:57
【问题描述】:

在我的 ubuntu 系统上安装了 PostgreSQL,当我尝试运行 bundle install 时出现以下错误。

有什么方法可以运行命令并安装所有必要的 gems

-- gem install pg -v '0.18.4'
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /home/mink7/.gem/ruby/2.3.0/gems/pg-0.18.4/ext
/home/mink7/usr/local/2.3.0/bin/ruby -r ./siteconf20160408-15866-1siay0w.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=/home/mink7/usr/local/2.3.0/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/mink7/.gem/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.18.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/mink7/.gem/ruby/2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /home/mink7/.gem/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.18.4/gem_make.out

我也跑了

sudo apt-get install gcc

并确保编译器是最新版本。

【问题讨论】:

标签: ruby-on-rails postgresql ruby-on-rails-4 ubuntu rubygems


【解决方案1】:

查看消息检查 libpq-fe.h... 否。

尝试安装 libpq-dev。 对于 Ubuntu 系统:

sudo apt-get install libpq-dev

那么你应该可以运行 bundle install 了。

【讨论】:

  • 如果你使用 Alpine linux(在我的例子中是 Docker 镜像),你应该安装 postgresql-dev。 apk add postgresql-dev
【解决方案2】:

我遇到了同样的错误,但消息如下:

正在检查 pg_config...否

所以按照上述解决方案,我运行如下:

dnf install libpq-dev   (Since I am using Fedora 23)

但收到此消息:

没有可用的软件包 libpq-dev。错误:找不到匹配项。

最初使用以下命令安装 postgresql:

dnf install postgresql-server postgresql-contrib

当我做which pg_config 时,我得到了这个:

/usr/bin/which: 没有 pg_config 在 (/usr/local/heroku/bin:/usr/local/rvm/gems/ruby-2.2.4/bin:/usr/local/rvm/gems/ruby-2.2.4@global/bin:/usr/local /rvm/rubies/ruby-2.2.4/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr /local/rvm/bin:/home/mayur/.local/bin:/home/mayur/bin)

所以我用这个命令再次安装了 postgresql:

dnf install postgresql-devel

现在运行which pg_config,输出/usr/bin/pg_config

那就试试bundle install:

使用原生扩展安装 pg 0.18.4...没有任何错误。

【讨论】:

    猜你喜欢
    • 2014-06-04
    • 1970-01-01
    • 2013-06-27
    • 2020-04-23
    • 2013-04-21
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多