我尝试在OSX上的heroku上的rails上安装ruby,我使用了this tutorial。它似乎在终端上安装得很好,但是在做完之后
$rails new myapp --database=postgresql
cd myapp
我做了这个
rails generate controller welcome
并收到错误:
Could not find gem 'spring (>= 0) ruby' in the gems available on this machine.
Run
捆绑安装to install missing gems.
按照说明操作后,我得到了
'An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.'
然后......
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
...
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.
一个类似的SO问题说通过更新XCode解决了问题,但我不认为这是我的问题。如果它还不明显,我对终端或ruby不太熟悉,所以我不确定如何处理这个问题。
编辑:
新错误消息
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/mahireusufzai/.rbenv/versions/2.1.1/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
*** 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.
...
/Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/2.1.0/mkmf.rb:541:in `try_link0'
from /Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/2.1.0/mkmf.rb:556:in `try_link'
from extconf.rb:39:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/pg-0.17.1 for inspection.
答案 0 :(得分:1)
您需要先安装postgresql开发库。它抱怨libpq-fe.h丢失了。
根据以下帖子中的答案尝试解决:Rails: Error installing pg gem
答案 1 :(得分:0)
尝试
yum install postgresql-devel
或
brew install postgresql
然后gem install pg
应该有效