在 OSX 上安装 PostgreSQL 以进行 Rails 开发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2271069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing PostgreSQL on OSX for Rails development
提问by Ganesh Shankar
I've spent several hours over the past few days trying to get PostgreSQL to play nice with RoR on my Mac.
在过去的几天里,我花了几个小时试图让 PostgreSQL 在我的 Mac 上与 RoR 配合得很好。
I've followed several tutorials using several different methods such as installing PostgreSQL manually and installing from various 1-click installers
我已经使用几种不同的方法学习了几个教程,例如手动安装 PostgreSQL 和从各种一键安装程序安装
However the all the different methods I tried failed on the last step of installing the pg gem. Very frustrating!
然而,我尝试的所有不同方法在安装 pg gem 的最后一步都失败了。非常令人沮丧!
Does anyone here have a tried and tested tutorial for getting this done? (Or would you like to write some instructions here...?)
这里有没有人有一个久经考验的教程来完成这项工作?(或者你想在这里写一些说明......?)
My environment is this: Macbook running OSX 10.6, PostgreSQL 8.4.1 server
我的环境是这样的:Macbook running OSX 10.6, PostgreSQL 8.4.1 server
回答by Ganesh Shankar
I think I've managed to find a way that works. I'm borrowing heavily from this great post1, but since they are installing a bunch of other stuff at the same time I'm going to write out what I did here for people who are just looking for the PostgreSQL install answer.
我想我已经设法找到了一种有效的方法。我从这篇很棒的帖子1 中大量借鉴,但由于他们同时安装了一堆其他东西,我将写出我在这里为那些只是寻找 PostgreSQL 安装答案的人所做的事情。
1Editor's note: Link seemed dead when I tried. Is this the one? http://blog.blackwhale.at/?p=175#PostgreSQLPlease fix if it is.
1编者注:当我尝试时,链接似乎已死。是这个吗?http://blog.blackwhale.at/?p=175#PostgreSQL如果是请修复。
Download PostgreSQL for Macand download the ‘Postgres.app' installer.
Create a user for your rails development (keep in mind that if you're sharing an application during development you'll probably want the same user between all members your dev team in order to avoid headaches)
sudo -u postgres /Library/PostgreSQL8/bin/createuser
Enter your Mac OS X system user name as role name, and make it a superuser.
Install the pg gem so Rails can talk to PostgreSQL
sudo env PATH=/Library/PostgreSQL8/bin:$PATH gem install pg
Configure your rails app to talk to PostgreSQL. You can either create a new application with:
rails *appname* -d postgresql (for Rails 3 -> rails new *appname* -d postgresql)
Or for an existing app, modify your
database.yml
file.
下载PostgreSQL for Mac并下载“Postgres.app”安装程序。
为您的 rails 开发创建一个用户(请记住,如果您在开发期间共享一个应用程序,您可能希望开发团队的所有成员都使用相同的用户,以避免头痛)
sudo -u postgres /Library/PostgreSQL8/bin/createuser
输入您的 Mac OS X 系统用户名作为角色名称,并使其成为超级用户。
安装 pg gem 以便 Rails 可以与 PostgreSQL 通信
sudo env PATH=/Library/PostgreSQL8/bin:$PATH gem install pg
配置您的 rails 应用程序以与 PostgreSQL 对话。您可以创建一个新的应用程序:
rails *appname* -d postgresql (for Rails 3 -> rails new *appname* -d postgresql)
或者对于现有应用程序,修改您的
database.yml
文件。
This worked for me without any hiccups. If anyone else tries using this method I'd be interested to hear some feedback on how it went for you.
这对我有用,没有任何问题。如果其他人尝试使用这种方法,我很想听听一些关于它如何为您服务的反馈。
回答by Tyler
On a 64-bit Mac (Snow Leopard with Core 2 Duo or newer) I had to compile PostgreSQL from source, as rails kept complaining that:
在 64 位 Mac(带有 Core 2 Duo 或更新版本的 Snow Leopard)上,我不得不从源代码编译 PostgreSQL,因为 Rails 一直抱怨:
*** Your PostgreSQL installation doesn't seem to have an architecture in common
with the running ruby interpreter (["ppc", "i386", "x86_64"] vs. [])
The architecture mismatch was probably bc I'd compiled rails from source, which defaulted to 64-bit. The binary installer on postgresql.org seemed only a 32-bit version. Setting ARCHFLAGS didn't fix this for me.
架构不匹配可能是因为我从源代码编译了 rails,默认为 64 位。postgresql.org 上的二进制安装程序似乎只有 32 位版本。设置 ARCHFLAGS 并没有为我解决这个问题。
Anyhow, if you download the [source][1] from postgresql.org and follow the instructions in the INSTALL file, it's fairly straightforward. You don't have to create a new user if you use your own account. I did have to create the sysctl.conf
file to expand shared memory - just google 'postgresql os x sysctl.conf'
无论如何,如果您从 postgresql.org 下载 [source][1] 并按照 INSTALL 文件中的说明进行操作,则相当简单。如果您使用自己的帐户,则不必创建新用户。我确实必须创建sysctl.conf
文件来扩展共享内存 - 只需谷歌“postgresql os x sysctl.conf”
回答by ErwinM
Old question, but still maybe i can help someone with this (rather simple) solution:
老问题,但也许我仍然可以帮助某人解决这个(相当简单的)解决方案:
gem install pg -- --with-opt-include=/opt/local/include/postgresql84/ --with-opt-lib=/opt/local/lib/postgresql84/
回答by prodigitalson
- Download and Install MacPorts
- fire up terminal
sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails
- 下载并安装 MacPorts
- 启动终端
sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails
回答by Francois
Thanks to Ganesh for the good awnser, my sudo url looked a bit diffirent :) here is what I havesudo -u postgres /Library/PostgreSQL/9.2/bin/createuser
感谢 Ganesh 提供的好 awnser,我的 sudo url 看起来有点不同 :) 这就是我所拥有的sudo -u postgres /Library/PostgreSQL/9.2/bin/createuser
回答by Yarin
Ryan Bate's Railscast on PostgreSQLwalks you through setting it up on a Mac with Homebrew. Very easy, worked for me on OSX 10.6.8.
Ryan Bate 的Railscast on PostgreSQL 将引导您在 Mac 上使用Homebrew进行设置。非常简单,在 OSX 10.6.8 上对我来说有效。