加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 错误:安装pg时出错:错误:无法构建gem原生扩

发布时间:2020-12-17 02:48:57 所属栏目:百科 来源:网络整理
导读:我克隆了一个rails repo,我现在正试图捆绑安装 背景: OSX El Capitan ruby?? 2.2.3p173(2015-08-18修订版51636) [x86_64的-darwin15] rails -v在Gemfile中列出的或本机上可用的任何gem源中找不到gem’pg( = 0)ruby’.运行bundle install以安装缺少的gem. bu
我克隆了一个rails repo,我现在正试图捆绑安装

背景:

> OSX El Capitan
> ruby?? 2.2.3p173(2015-08-18修订版51636)
[x86_64的-darwin15]

rails -v在Gemfile中列出的或本机上可用的任何gem源中找不到gem’pg(> = 0)ruby’.运行bundle install以安装缺少的gem.

bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
...
Using jbuilder 2.3.2
Using jquery-rails 4.0.5


Your user account isn't allowed to install to the system Rubygems.
You can cancel this installation and run:

    bundle install --path vendor/bundle

to install the gems into ./vendor/bundle/,or you can enter your password
and install the bundled gems to Rubygems using sudo.

Password:
Installing pg 0.18.3 with native extensions

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

    /usr/local/opt/ruby/bin/ruby -r ./siteconf20151105-3981-12lvpnr.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails,please try again with
 --with-pg-config=/path/to/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.

Provided configuration options:
    --with-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/local/Cellar/ruby/2.2.3/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

extconf failed,exit code 1

Gem files will remain installed in /var/folders/lj/c7hfzz254cd3lt2nxscv_wgw0000gn/T/bundler20151105-3981-149quvepg-0.18.3/gems/pg-0.18.3 for inspection.
Results logged to /var/folders/lj/c7hfzz254cd3lt2nxscv_wgw0000gn/T/bundler20151105-3981-149quvepg-0.18.3/extensions/x86_64-darwin-15/2.2.0/pg-0.18.3/gem_make.out
An error occurred while installing pg (0.18.3),and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.3'` succeeds before bundling.

此时我运行gem install pg -v’0.18.3′

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

    /usr/local/opt/ruby/bin/ruby -r ./siteconf20151105-4004-1ylkqpt.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails,exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.2.0/gems/pg-0.18.3 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0/pg-0.18.3/gem_make.out

我的gem文件底部有以下内容

# Use sqlite3 as the database for Active Record
group :development,:test do
  gem 'sqlite3'
end

group :production do
  gem 'rails_12factor'
  gem 'pg'
end

我正在看下面的SO question,但似乎无法弄清楚相当于OSX.

解决方法

似乎你没有安装Postgres.使用以下内容安装它:

brew install postgres

(如果你有Homebrew)

然后尝试再次编译gem扩展.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读