Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having Trouble Using "brew link" to switch between PostgreSQLs

I want to run a Rails app on Heroku so I installed PostgreSQL on my Snow Leopard machine using Homebrew. Currently, brew installs 9.1.2 into /usr/local/Cellar/postgresql. After some research, I discovered that the free, shared version of Heroku requires 8.3.x. While homebrew-alt doesn't have 8.3, it does have 8.4 so I downloaded it instead and it installed into /usr/local/Cellar/postgresql8. I then confirmed that I am able to create and run databases on each version. Thinking that I could use "brew [link | unlink] to switch back and forth, I ran "brew unlink postgresql8" and then "brew link postgresql". However, running the latter command results in this error:

Linking /usr/local/Cellar/postgresql/9.1.2... Error: Cannot link postgresql Another version is already linked: /usr/local/Cellar/postgresql/9.1.2

Is there any way to do this (switch back and forth) or am I misunderstanding how brew link/unlink is supposed to be used?

By the way, "brew list" shows "postgresql" and "postgresql8" so I don't think it's the case that I should say "brew link postgresql9".

Thanks.

like image 322
Jim Avatar asked Jan 07 '12 00:01

Jim


1 Answers

Thanks, mipadi! That did the trick. There was only one additional thing that I needed to do. The 'brew switch' command assumes all versions of postgresql are installed in /usr/local/Cellar/postgresql. That was not the case with version 8.4.8 as it was installed in /usr/local/Cellar/postgresql8. Consequently I had to create a symbolic link to point to this older version:

cd /usr/local/Cellar/postgresql
ln -s ../postgresql8/8.4.8 8.4.8

Naturally, it also makes sense to keep your database clusters in separate directories:

/usr/local/var/postgres/8.4.8
/usr/local/var/postgres/9.1.2
like image 185
Jim Avatar answered Oct 15 '22 23:10

Jim