ruby-on-railspostgresqlpathrubygems

$PATH confusion Postgres and Rails on OSX Lion


Rails and all my gem files + homebrew installs have been working fine up until this point.

I ran

homebrew install postgresql 

and was following the prompts pretty much as indicated in this video but it kept giving me error messages saying there is a server already running. I checked

which psql

in the terminal and it reported a

 usr/bin 

location rather than

usr/local/bin 

indicating I was using the postgres that comes with osx not the new homebrew install.

When I attempted to start the database server I recieved an error message saying the server is already running. There is a mention of this error message in the postgres help documentation but no real working solution.

Attempting brew doctor confirmed that i needed to change my PATH in .bash_profile.

I came across this little snippet here on stack overflow for the .bash_profile edit.

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin

I saved the file and managed to get postgres up and running fine but then when I went to start a new rails app.

rails new blog -d postgresql 

it says

Rails is not currently installed on this system. To get the latest version, 
simply type:

$ sudo gem install rails

You can then rerun your "rails" command.

Any attempt to install does not work until i change the bash_profile file back to what it was before.

If I change it back postgres has the same issue again saying there is already a server running.

Also I thought it might be a launch agent or something but I don't think there are any that are set up.

I figure either something is installed in the wrong place or I have to add something to the .bash_profile?


Solution

  • Don't set your $PATH explicitly. You should append or prepend to it instead:

    # In your .bash_profile
    export PATH="/usr/local/bin:$PATH"
    

    My guess is that you either use RVM or rbenv. If you change your path to /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin explicitly then RVM or rbenv won't be in your path.