简体   繁体   English

在雪豹上安装Rails 3.1和Postgresql

[英]Setup Rails 3.1 and Postgresql on Snow Leopard

I have spent countless number of hours trying to setup PostgreSql on my Intel Mac. 我花了无数小时试图在我的Intel Mac上安装PostgreSql。

I am able to install Rails and all but PostgreSql would not get installed on my Mac. 我能够安装Rails,但除了PostgreSql之外,其他都无法在Mac上安装。

Anybody has any solution or any tutorial which I can follow to install it ?? 任何人都有任何解决方案或任何教程,我可以按照它们进行安装?

PS I just started using Mac as my development machine. PS我刚开始使用Mac作为开发机器。 I have been using Windows before that ! 在此之前,我一直在使用Windows!

Ok I had to do a little more research with a fresh mind and I am now able to solve the problem myself. 好吧,我不得不重新研究一下,现在我可以自己解决问题了。 Here is the solution : 这是解决方案:

Install Homebrew using this command : 使用以下命令安装Homebrew:

ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"

Once installed write this in your terminal : 安装完成后,将其写入您的终端:

brew install postgres

If this is your first install ( which was the case with me ) than type this in terminal after the above step: 如果这是您的第一次安装(我就是这种情况),则在上述步骤之后在终端中键入以下内容:

$ initdb /usr/local/var/postgres

To start the postgresql type this in terminal: 要启动PostgreSQL,请在终端中输入以下内容:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

After the above step type this : 在上述步骤之后,键入:

ps auxwww | grep postgres

If the result of the above command in terminal looks like this than that means the postgresql is installed correctly : 如果上述命令在终端中的结果看起来像这样,则说明postgresql已正确安装:

26000   0.0  0.1  2445860   1556   ??  Ss    1:59AM   0:00.05 postgres: autovacuum launcher process
25999   0.0  0.0  2445728    512   ??  Ss    1:59AM   0:00.15 postgres: wal writer process
25998   0.0  0.0  2445728    912   ??  Ss    1:59AM   0:00.21 postgres: writer process  

25996   0.0  0.1  2445728   2508   ??  S     1:59AM   0:00.15 /usr/local/Cellar/postgresql/9.0.4/bin/postgres -D /usr/local/var/postgres

26257   0.0  0.0  2435548      0 s000  R+    2:19AM   0:00.00 grep postgres

Create a user and database: 创建一个用户和数据库:

createuser username

createdb -Ousername -Eutf8 databasename

To login to postgresql use this command: 要登录到postgresql,请使用以下命令:

psql -U username databasename

If you are using it with rails you can install the gem like this : 如果将它与滑轨配合使用,则可以这样安装gem:

sudo env ARCHFLAGS="-arch x86_64" gem install --no-ri --no-rdoc pg

If you would like to stop the PostgreSQL service use this command : 如果您想停止PostgreSQL服务,请使用以下命令:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

Hope this will help others in saving the time of going through different resources to come with the solution like I did :) 希望这将帮助其他人节省像我一样通过解决方案来提供不同资源的时间:)

Try using Cinderella . 尝试使用Cinderella That will give you the whole stack (including MongoDB, Redis, and a whole bunch of other stuff) in one nice neat bundle in ~/Developer . 这将在~/Developer中的一个整洁的捆绑包中为您提供整个堆栈(包括MongoDB,Redis和一堆其他东西)。 You're better off using custom builds of all your development tools so that you don't have to worry about what version of anything comes with the system and what an upgrade might to do your OS. 您最好使用所有开发工具的自定义版本,这样您就不必担心系统附带什么版本的东西以及可以对您的操作系统进行什么升级。

References: 参考文献:

A few other notes to add to your instructions: 要添加到您的说明中的其他注意事项:

There is a good post at Russ Brooks Blog on installation which validates much of what you have above. Russ Brooks博客上有一篇关于安装的好文章,可以验证您上面的内容。

There are a set of admin tools available at pgadmin.org which will allow you to browse your database through a simple GUI on the Mac pgadmin.org上有一组管理工具,可让您通过Mac上的简单GUI浏览数据库。

If you use the admin tools you should install the instrumentation pack with the following: 如果您使用管理工具,则应使用以下内容安装工具包:

psql -d postgres < /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql

where the exact command obviously depends on the version of postgresql you are using. 确切的命令显然取决于您使用的postgresql的版本。

If you are using postgres with rails and bundler then make sure the "pg" gem is in your gem file and run bundler with the following command immediately after you add it: 如果将postgres与rails和bundler一起使用,请确保在您的gem文件中包含“ pg” gem,并在添加后立即使用以下命令运行bundler:

env ARCHFLAGS="-arch x86_64" bundle install

This will do the same as your 'gem install' command above. 这与上面的“ gem install”命令相同。 After you run it for the first time you no longer need to use the 'env ARCHFLAGS="-arch x86_64"' when you run bundler. 首次运行它后,在运行捆绑程序时不再需要使用'env ARCHFLAGS =“-arch x86_64”'。

I have used MacPorts for most of my server/low level program installations (PostgreSQL, MySQL, etc.). 我已经在大多数服务器/低级程序安装(PostgreSQL,MySQL等)中使用了MacPorts If you choose to go that route, you can then follow this blog post/tutorial on installing PostgreSQL via MacPorts onto your Mac. 如果您选择这种方式,则可以按照此博客文章/教程中的说明 ,通过MacPorts将PostgreSQL安装到Mac上。 One thing to note on the PostgreSQL link: when following along, change the instances of 83 to 90. For example, you will see this in his steps: PostgreSQL链接上需要注意的一件事:继续时,将83的实例更改为90。例如,您将在他的步骤中看到这一点:

sudo port install postgresql83 postgresql83-server

You can instead, type this to get the newest version of PostgreSQL 您可以改为键入此命令以获取最新版本的PostgreSQL。

sudo port install postgresql90 postgresql90-server

I would also recommend grabbing a program such as Navicat for PostgreSQL Lite . 我还建议您为PostgreSQL Lite抓取一个程序,例如Navicat It's free and nice to have to manage your local PostgreSQL DBs. 管理本地PostgreSQL数据库是免费的,而且很好。

If you don't want to go with MacPorts, there's a similar alternative called HomeBrew that's quite popular ... I'm just too lazy to switch from MacPorts :). 如果您不想使用MacPorts,则有一个类似的替代产品叫做HomeBrew,它很受欢迎……我懒得从MacPorts切换到:)。

I had luck downloading and installing it straight from the site: 我很幸运直接从该站点下载并安装了它:

http://www.postgresql.org/download/macosx http://www.postgresql.org/download/macosx

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

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