升级到Mountain Lion后,我遇到了很多关于Rails的麻烦。
到目前为止,我试图解决这些问题,并在网上搜索几个小时,我已经做了以下工作以确保我的系统在升级后具有运行rails的所有依赖项:
ruby 1.9.2p290(2011-07-09修订版32553)[x86_64-darwin10.8.0]
我还发现Mountain Lion与Postgres存在一些问题所以我看到this post并发现我需要将此行添加到我的Bash配置文件中:
export PATH="/usr/local/bin:/usr/bin:$PATH"
现在我转到我升级之前在Snow Leopard上运行正常的Rails应用程序,当我在命令行运行rails s
时出现以下错误:
AM@~/Documents/RailsWS/app0815 >gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... *** 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=/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
/Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:368:in `try_do':
The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:41:in `<main>'
Gem files will remain installed in /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.14.1 for inspection.
Results logged to /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.14.1/ext/gem_make.out
当我转到Rails应用程序并尝试bundle install
时,它在pg安装时失败。
答案 0 :(得分:13)
从http://www.enterprisedb.com/products-services-training/pgdownload#osx
下载postgresSQL安装程序然后让你的路径看起来像这样:
PATH=$PATH:/Library/PostgreSQL/9.0/bin/ gem install pg
这样做!
注意:请在路径中正确指定postgreSQL安装版本。
在OS X上使用Homebrew:
使用以下方法安装postgresql:
brew install postgresql
然后使用以下方法安装gem:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
在带有MacPorts的OS X上:
gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
希望这有帮助!
答案 1 :(得分:12)
正如banditKing在他的回答中所说,需要告诉宝石在哪里找到postgres二进制文件。您可以使用Heroku(http://postgresapp.com)中优秀且简单的postgres.app附带的二进制文件来安装此gem而不是EnterpriseDb版本。 EnterpriseDB版本很棒,但是涉及到dev机器的安装。
在您的系统上下载 Postgres.app ,并将内部bin目录添加到您的路径中。我把它放在/Applications/Postgres.app
中,所以我用了
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
在10.8.2,Ruby 1.9.3,pg-0.14.1和XCode CLI工具上为我工作
答案 2 :(得分:0)
或者,使用Postgres应用程序。 IMO,它是在Mac上启动和运行PostgreSQL和Rails的最简单,最快捷的方法。
答案 3 :(得分:0)
安装Mavericks后bundle update
在pg gem上抛出错误。
我使用Brew来管理我的软件包并且已经安装了postgresql,但我仍然收到'no pg_config'错误。
修复只是brew uninstall postgresql
,然后是brew install postgresql
。之后我立即成功运行bundle update
。