Installing PostgreSQL on OSX for Rails development - ruby-on-rails

I've spent several hours over the past few days trying to get PostgreSQL to play nice with RoR on my Mac.
I've followed several tutorials using several different methods such as installing PostgreSQL manually and installing from various 1-click installers
However the all the different methods I tried failed on the last step of installing the pg gem. Very frustrating!
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

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 Editor's note: Link seemed dead when I tried. Is this the one? http://blog.blackwhale.at/?p=175#PostgreSQL Please fix if it is.
Download PostgreSQL for Mac and 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.
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.

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:
*** 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.
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'

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/

Download and Install MacPorts
fire up terminal
sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails

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

Ryan Bate's Railscast on PostgreSQL walks you through setting it up on a Mac with Homebrew. Very easy, worked for me on OSX 10.6.8.

Related

Is there a simple way to install rails on OS X 10.11 El Capitan

The instructions for older OS don't seem to work well with system integrity protection enabled on OS X El capitan 10.11.1
What options for a http://railsinstaller.org or another one package, streamlined install to get rails running?
first of all you need ruby... as you are on OS x EL capitan you already have ruby... so first step done... ruby is the programming language... rails is the framework ... so you already have the language now you want the framework...
next is you need to install bundler (package manager for ruby):
gem install bundler
then you can install rails:
gem install rails
so now you can create a new project with:
rails new my_app_name
when you did this you will recognize that after the creation of a bunch of things it executes bundle install... so afterwards you should be able to start your app with:
rails s
If an error occurs during the installation just lookup the error by a quick google search... most of the time it is just a dependency that you are missing... also depending on which tutorial you tried you may need to start mysql first... or execute something like: rake db:create (create a database in your chosen database) and afterwards: rake db:migrate to create some tables (but this depends on the previous tutorial) try to get the welcome page from rails first ... you should get it in your browser with the adress: localhost:3000
Apple installs /usr/bin/rails to walk you through the official installation instructions as part of the core OS install if you ever run the program. Many of the old instructions will break since they don't play well with System Integrity Protection that's new on 10.11.
First make sure your command line tools are installed:
xcode-select install
Then follow the instructions (if any) you get from checking on the installed version of rails:
rails --version
this is a great site : https://gorails.com/setup/osx/10.11-el-capitan
However if you experience
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
on terminal after using gem install you must install command line tool via Xcode -> Preferences -> Downloads or https://developer.apple.com/downloads/
if you have newer Xcode versions
If you're not using homebrew and rvm, I implore you to do so! Now that you're on a fresh install, this may be the right time to get these habits down... I know it has a learning curve, but both will make your life incredibly easier later down the road, specially rvm! :)
This article describes how a user got it done... they basically compiled a ruby on el capitan.
http://www.railsbling.com/posts/el-capitan-homebrew-ruby-qt5-java/
rvm is way better than what any railsinstaller or shellscript would...

Rake db:create fails on Library not loaded

I was running PostgreSQL 9.1, installed from Postgres (/Library/PostgreSQL/9.1) - ie not homebrew etc and on Mac OSX Leopard.
I upgraded to Snow Leopard and then immediately to Mountain Lion and had a mass of problems with gems failing to build etc, but got them fixed
Rails server crashed on startup with pg issues & I tried everything I could find but could not fix the prob - fixes included links etc, which may still persist (hence this background info might inform the solution)
I uninstalled postgresql 9.1 and installed Postgres App
Now on rake db:create I get the following:
rake aborted!
dlopen(/Users/mitch/.rvm/gems/ruby-1.9.2-p320#tme-3.2.11-mltest/gems/pg-0.17.0/lib/pg_ext.bundle, 9): Library not loaded: #loader_path/../lib/libpq.5.dylib
Referenced from: /Users/mitch/.rvm/gems/ruby-1.9.2-p320#tme-3.2.11-mltest/gems/pg-0.17.0/lib/pg_ext.bundle
Reason: no suitable image found. Did find:
/usr/local/lib/libpq.5.dylib: mach-o, but wrong architecture - /Users/mitch/.rvm/gems/ruby-1.9.2-p320#tme-3.2.11-mltest/gems/pg-0.17.0/lib/pg_ext.bundle
I'm running rvm (as u can see) and after the OS upgrade created a new gemset and installed Ruby
I've changed my path to reflect the advice of Postgresql App, after the OS upgrade I installed Xcode 5 and the command line tools as advised and I think my database.yaml file is ok
I suspect the problem might be connected with sym-links made earlier in the process, but I'm stuck to find the solution
Sounds like something has gone wrong in your Ruby installation. Try reinstalling Ruby Enterprise Edition via RVM:
rvm reinstall ree
I was experiencing the same issue with a different version of libpq. What I ended up doing is creating a link to the correct file:
sudo ln -s /Applications/Postgres93.app/Contents/MacOS/lib/libpq.5.6.dylib /usr/local/lib/
My previous answer was deleted as it wasn't originally an answer, just a confirmation of a similar issue. Hope this helps!
In the end I think this was tied up with the fact that Mountain Lion ships with Postgresql rather than MySQL as per previous OSX versions.
I couldn't make sense of the Postgres App, so I uninstalled it and also uninstalled the version of Postgresql that shipped with ML and then did a Homebrew install of the latest version of Postgresql (which places it in a different place than if you install it direct from the Postgresql site).
This seemed to straighten everything up

Rails Server broken after PostgreSQL download

Operating System I am using is Mac OSX Mountain Lion.
First I will give some back story on how this cluster F started. I am going through a Ruby on Rails Web development book. I want to use PostgreSQL as my server. Before today I was using sqlite3. I downloaded PostgreSQL 9.1 from there website. I used the DMG installer. Once I was done with the install process it asked me to re-boot because of some sort of memory problem, I did that and it installed without error.
The problem started when I tried to use the "Rails Server" command in the terminal. This is what I got (I tried to strip out the unimportant stuff which would clutter everything up)
/Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/pg-0.12.2/lib/pg.rb:4:in `require': dlopen(/Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: /usr/lib/libcrypto.dylib (LoadError)
Referenced from: /usr/lib/libpq.5.dylib
Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libcrypto.0.9.8.dylib provides version 0.9.8 - /Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/pg-0.12.2/lib/pg_ext.bundle
...
from /Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/commands.rb:50:in
I have read through the out put and I have done a lot of Google searching, and what I have found is that it's a problem with which version of libcrypto the server is fetching. Or something about the libssl. I have gone through the solutions on google and nothing seems to be working. Hopefully someone has had the same problem I have, and can help me.
Thanks in advance! -Chris
I really recommend you to use Homebrew to install postrgresql. It helps you to install all proper dependencies for version which correctly works with rails.
$ brew install postgresql
Do not forget to follow after install instructions from homebrew
Are you sure you installed PostgreSQL server/rubygem successfully? From the stack trace I think there's a problem about it.
If your PostgreSQL server/rubygem are working well, then switch another webserver, mongrel/thin are both OK, both have better performance than the default rails server(webrick) and easy to use.

Installing RoR stack on Mac OS X

I just got a new MacBook Pro and would like to install / upgrade the the Ruby on Rails stack specifically. My question is whether I should sudo all the installs / upgrades. The usual suspects of what I plan to install / upgrade are: Ruby, Gems, Rails, MySQL, sqlite3, PostgreSQL, RVM, Nginx, Passenger. I understand that RVM can be installed with different levels of access, root vs admin user, etc. Anyone knows what's the preferred way of installing RVM?
UPDATE
I know that LAMP isn't RoR, I just thought it was more inclusive seeing that it included web server, database, etc. Anyway, my bad, I have removed it from the post to avoid confusion. I have installed all the various components before, so this isn't a question about how to install them, this is a question about if I should install them as root or just the usual admin user.
Apache comes installed; edit the configuration file here: /private/etc/apache2/httpd.conf. To start/stop apache, open your System Prefrences.app, go to Sharing, and click the checkbox next to Web Sharing.
For MySQL, simply download the dmg and install http://dev.mysql.com/downloads/mysql/
sqlite3 comines installed
PostgreSQL: http://www.postgresql.org/download/macosx
How to install RVM: http://rvm.beginrescueend.com/rvm/install/
Update your ruby gems: sudo gem update --system
Update rails: gem update rails
Bonus: Awesome package manager for MacOS: https://github.com/mxcl/homebrew. You don't actually need this for the things you listed above, but I would highly recommend this if you plan on compiling/installing any additional packages on your system. (You'll need to install Xcode for this.)
PS: You don't actually mean "LAMP" as the P stands for PHP.
I know this is a little old, but the same concept applies. Excellent tutorial on how to do what you're asking for the best way.
Hivelogic Tutorial

One-Click install for Ruby/Rails/SQLite?

I'm used to the One-Click install local environments of MAMP. Is there a Ruby equivalent... a download that you run and instantly get the most current versions of Ruby, Rails, SQLite running locally?
I'm using a Mac, running Leopard, and am aware that all of the aforementioned technologies ship with Leopard (except maybe SQLite). The books that I have reference newer versions and the last thing I need is to try to retrofit a tutorial to work with my version.
And one more less important question: What are "Gems" and is that something that I need to make sure is fully updated too?
Installation is pretty confusing when you first start with Rails! Even though a lot of what you need is already installed if you are using Mac, personally I found it really hard to find come concise information on how to best go about setting things up.
Since I didn't want anyone else to go through the headaches that I had when configuring their Mac development environment, I've written a 7 step guide to installing Ruby on Rails, MySQL, Apache with PHP, and phpMyAdmin on OSX Leopard. In short, everything you should need to get developing locally on your Mac!
Here's the link:
http://waavoo.com/2009/7-step-guide-installing-ruby-on-rails-mysql-apache-php-phpmyadmin-intel-mac-os-x-leopard/
Hope that helps!
Take a look at FiveRuns Install. It's a free Ruby on Rails stack that you can download.
RubyGems is the Ruby standard for publishing and managing third party libraries. Check out the User Guide.
Have fun!
I have no idea what mac os are you in but Leopard (10.5.x) already have ruby installed, all you need is to updated the gems using
gem update rails
in your command line.
if you're on Tiger (10.4.x) the installation is broken, and please follow this link.
You should also have a look at Phusion Passenger - this, along with the prefpane, allows you to have apache VirtualHosts set up the easy way.
Current versions of Rails are designed to work (for development) without needing an AMP -style stack, by using SQLite and a small Ruby Web server, so if you will only be doing Rails development you don't need to set up a stack - you can just type "rails" and it will work.
BUT the versions of RubyGems and Rails shipped with Leopard are now outdated, though, so you'll need to upgrade these before you go too far. There's an article that I wrote on setting up a Mac for development here, but the minimum commands go like this:
sudo gem install rubygems-update
sudo update_rubygems
sudo update_rubygems (yep, twice)
sudo gem update --system
These get RubyGems up to the current release, so that you can upgrade Rails safely. To do that, type:
gem update rails
The last command doesn't have sudo, because if you omit it, current versions of RubyGems will install a clean copy of the gems into your home directory, leaving the system versions untouched.
Finally, amend the .profile file in your home directory, so that the line with PATH in it says:
export PATH=$HOME/.gem/ruby/1.8/bin:$PATH
Close up any terminal windows for this to take effect. The utilities provided by the gem packages in your home directory will now have precedence over the system versions.
This means that you can type "rails" and the latest version will run, but you haven't messed with any of the software provided by Apple (apart from the system copy of RubyGems).
To upgrade your private copy of Rails whenever a new version comes along in future it's just this again:
gem update rails
just refer this....
http://wiki.rubyonrails.org/getting-started/installation/windows#installing_ruby_on_rails_on_windows
BitNami RubyStack is exactly what you are looking for http://bitnami.org/stack/rubystack

Resources