2012-12-07 180 views
1

我在開發一個使用sqlite3的rails應用程序。我想把它推到Heroku。在Heroku的教程,它說,我要第一個變化:在Ubuntu上安裝pg gem

gem 'sqlite3' 

gem 'pg' 

和運行

bundle install 

我得到這個錯誤:

Installing pg (0.14.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. 
... 
Can't find the PostgreSQL client library (libpq) 
*** 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. 
... 

下一個我嘗試瞭解決方案here

running gem install pg -- --with-pg-config= /usr/bin/pg_config 

我也嘗試運行:

sudo apt-get install postgresql 
sudo apt-get install libpq-dev 

gem install pg 

工作正常..

bundle install 

仍然給我相同的錯誤

注:我使用的是RVM

+0

我認爲我使用rvm的事實是讓事情變得複雜,所以沒有任何關於SO的解決方案...... – shane

回答

1

你嘗試

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

group :production do 
    gem 'pg' 
end 

在你的Gemfile,這樣就可以在開發使用SQLite,當你推的Heroku作爲生產它將是第pg。

+0

yes試過這個。然後'捆綁安裝'..仍然得到相同的錯誤 – shane

+1

@shane:你指定了'--without'選項嗎?例如'bundle install --without = production'? – mipadi

+0

我做到了。這種方式'捆綁安裝'進展順利,但當我想推到heroku ...我仍然得到: 更新Gemfile.lock版本控制。 您已添加到Gemfile中: * pg 您已從Gemfile中刪除: * sqlite3 – shane

0

您的Gemfile更改爲以下:

gem 'sqlite3', :group => :development 
gem 'pg', :group => :production 

這樣,你會在開發中使用本地SQL。 Heroku會忽略sqlite gem,而是使用Postgres。

+0

這是一種方法。但它沒有解決不能在本地安裝postgresql的問題。用戶應該能夠這樣做,如果他們願意的話。 – dcow

+0

你是對的,但我不認爲這是他的要求。 「我正在開發一個使用sqlite3的rails應用程序,我想把它推到Heroku上。」 通常的做法是使用sql進行開發,並使用pg推送到heroku。 Heroku的指示轉移到開發工作到postgres可以忽略。 – Shaun

+0

當然,我只是想確保OP知道區別(= – dcow