[英]gem install pg giving Gem::Ext::BuildError: ERROR: Failed to build gem native extension in ruby '2.2.3' and 'rails', '4.2.7.1' in ubuntu 18.04 LTS
[英]PG gem won't install in Rails app: Gem::Ext::BuildError: ERROR: Failed to build gem native extension
我正在尝试将我的 Rails 应用程序部署到 Heroku 并且当我将pg
gem 添加到我的 gemfile 并运行bundle install
时出现错误:
An error occurred while installing pg (1.1.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.1.3'` succeeds before bundling.
我的 gemfile 的底部如下所示:
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
end
group :production do
gem 'pg'
end
当我运行gem install pg
时,我得到以下信息:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/scott_imunro/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-1.1.3/ext
/home/scott_imunro/.rbenv/versions/2.4.2/bin/ruby -r ./siteconf20181115-1119-1gb3plu.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
--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/scott_imunro/.rbenv/versions/2.4.2/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/scott_imunro/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-1.1.3/mkmf.log
extconf failed, exit code 1
我正在为 Windows 10 运行带有 Ubuntu bash 的 Rails 5。任何想法如何解决此错误?
我认为您需要在安装gem之前执行以下操作
sudo apt-get install libpq-dev
然后执行gem install pg -v '1.1.3'
-v'1.1.3 gem install pg -v '1.1.3'
或者只是bundle install
如果你在GEMFILE中有gem。
这可能是由于缺少依赖性。 在终端gem install pg -v '1.1.3'
手动运行命令,看看你得到了什么输出。
您可能错过了gem的先决条件库/标题。 尝试:
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev postgresql-client-common postgresql-client libpq-dev
可能值得一看这篇文章: https : //medium.com/@colinrubbert/installing-ruby-on-rails-in-windows-10-w-bash-postgresql-e48e55954fbf
我也面临同样的问题,问题是你的Linux安装需要安装PostgreSQL的开发库才能构建gem。
以下是我解决问题的方法
打开终端并运行以下命令
sudo apt-get install libpq-dev
然后使用此命令再次尝试安装PostgreSQL gem
gem install pg
就这样。
我希望这有帮助
答案在您得到的反馈中:
No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config
这正是您需要做的。
pg_config
位于postgres
和psql
所在的同一目录中,因此请使用which postgres
或which psql
来查找它。
然后运行(以我系统上的路径为例——用你找到的替换它):
gem install pg -- --with-pg-config=/usr/local/opt/postgresql@11/bin/pg_config
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.