简体   繁体   English

Ubuntu 14.04-安装pg(0.18.2)时发生错误,并且Bundler无法继续

[英]Ubuntu 14.04 - An error occurred while installing pg (0.18.2), and Bundler cannot continue

This issue doesn't let me go ahead and I don't know whether it's possible for me to deploy my Rails App ever on Heroku. 这个问题不能让我继续前进,我也不知道我是否有可能在Heroku上部署我的Rails应用程序。

When I try bundle install by having gem 'pg' in my Gemfile it gives following error. 当我尝试通过在Gemfile中包含gem'pg gem 'pg'进行bundle install ,出现以下错误。

An error occurred while installing pg (0.18.2), and Bundler cannot continue.

Make sure that gem install pg -v '0.18.2' succeeds before bundling.

However, when I try sudo gem install pg it says Successfully installed pg-0.18.2 1 gem installed 但是,当我尝试sudo gem install pg它说Successfully installed pg-0.18.2 1 gem installed

But when I try to run the app locally or deploy on Heroku it gives me the same error again. 但是,当我尝试在本地运行该应用程序或在Heroku上进行部署时,它再次给我同样的错误。 By using sqlite3 in development mode, all is well, but the same issue occurs on Heroku because Heroku doesn't support sqlite3. 通过在开发模式下使用sqlite3 ,一切都很好,但是在Heroku上也会发生相同的问题,因为Heroku不支持sqlite3。

Do you have PostgreSQL installed locally? 您在本地安装了PostgreSQL吗? If not, that might be the reason for that (having gem 'pg' is not enough to install it locally). 如果不是,那可能就是原因(拥有gem 'pg'不足以在本地安装它)。 You will have to run sudo apt-get install postgresql postgresql-contrib to install. 您将必须运行sudo apt-get install postgresql postgresql-contrib进行安装。

You do not need it installed locally to push to Heroku though...as long as you have gem 'pg' . 但是,只要有gem 'pg'就不需要在本地安装它来推送到Heroku。 You can do so by setting up a different group in your Gemfile specifically for production. 您可以通过在Gemfile中设置专门用于生产的其他组来实现。 Something like: 就像是:

group :development, :test do
  gem 'sqlite3',     '1.3.9'
end
group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

first thing is you must include the pg gem in production and sqlite in development and test environment in gem file 第一件事是您必须在生产中包含pg gem,在开发和测试环境中将sqlite包含在gem文件中

group :development, :test do
  gem 'sqlite3'
end
gem 'pg', group: :production

then bundle gems excluding the production environment 然后将宝石捆绑在生产环境之外

bundle install --without production

you could then commit and push on the heroku. 然后您可以提交并推动heroku。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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