I'm trying to locally start my rails server
but do I have to start my postgresql db each time I want to rails s?
I'm new to rails so I'm not sure how this works. I remember not having to do such a thing on something I've worked on before..
As mentioned in other answers you have to make sure that Postgres is runnign and serving your database. This is not handled by Rails.
Usually you would configure the Postgres server as an OS background service that starts with your system. Which operating system do you use? In case it's MacOS and you're already using Homebrew, I'd recommend using Hombrew services. You can read more about it here: https://github.com/Homebrew/homebrew-services
Basically you'd tell Homebrew to start postgres with your system, like this: brew services start postgres
You can use system commands to run postgresql server automatically on system boot
sudo systemctl enable postgresql
or
sudo update-rc.d postgresql enable
However it also belongs on how you install postgres
Related
I installed postgresql. I put the localhost port to 3000 on pgadmin. Then it started to throw this error since the localhost port for my ruby app is also at port 3000.
Address already in use - bind(2) for "localhost" port 3000 (Errno::EADDRINUSE
I tried to uninstall it and the error still comes up. I tried to delete pgadmin. I tried to set an environment variable export PGPORT=5432. After all this the error still comes up. I just want to get rid of postgres and re-install everything to see what went wrong. I am completely confused. I am faily new with ruby and postgres. I usually use node mongodb etc.
Questions:
What is the best way to get rid of postgresql and reinstall it?
Any other ideas on how to edit the port?
How to delete db on postgresql?
I know it sounds like I am all over the place because I am right now. I just want to start fresh. So please any help.
Best way to install and use PG/Mongo/MySql on Mac OSX is Brew.
If brew not installed, install it by copy/pasting into Terminal.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install Postgresql
brew install postgresql
To use DB (run/restart/stop)
brew services list
brew services start postgres
brew services stop postgres
you may also use different port.
rails s -p 81
if you want to always start with different port..create Rakefile and add a task..
task :server81 do
`bundle exec rails s -p 8081`
end
you can use it directly by rake server81
I'm trying to get a Ruby on Rails Web Application running on a server at school, and I need sudo privileges to do so. For this, I also need PostgreSQL installed as well.
I know that after installation, all that I'll need for PostgreSQL is the usr/local/pgsql/bin, usr/local/pgsql/inlcude, usr/local/pgsql/lib, and so on.. but I'm not particularly sure what kind of privileges I'm going to need during installation.
Also, is it possible for me to install Ruby on Rails without any sudo privileges?
The reason that I can't do everything as a root is because its a school server, and giving a student root access isn't particularly something that the server admin should do. She has to edit the /etc/sudoers file and assign me root access to the appropriate folder(s).
I believe if you use Ruby Version Manager you don't need sudo privileges as it just installs everything on your home directory. Also check out this answer: how to install gems without sudo
As for PostgreSQL you could use Homebrew for the install. If you are still having difficulty you should check out the detail PostgreSQL installation guides.
I am using PostgreSQL 9.1, which I installed using the DMG provided on the Postgres website. So, my Postgres installation is in /Library/Postgres/9.1.
I am pretty sure my Postgres server is running, but when I run rake db:migrate the rake is aborted with this error:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Why is "rake" searching /var/... and not using my installation of Postgres?
Can you supply the link from which you actually downloaded Postgres? It seems like your instance of Postgres has a differently-named socket file than Rails expects, so Rails is unable to find it.
One option is to find the socket that does exist on your system and create a symlink to it from the location mentioned in the output. But my suggestion is to delete this instance of Postgres and simply install it again using Homebrew since you seem to be using OSX. Installation using Homebrew is straightforward: brew install postgresql. After completing the installation just follow the steps listed in the command line output to complete the installation.
Also, if you are using the Postgres.app provided by Heroku you may want to check the documentation.
I got a rails app that requires redis, mongod, and postgres before starting with rails s. I do not like open several tabs on my terminal and open these services one by one. Is there a way to run everything with one command/script? Is there a specific gem that might help with this? Thanks.
one way is mentioned by #Tres with using the foreman gem. If you are using rvm you can use a .rvmrc file in your project. There you can simply define some shell commands like
mongod --port 23017
postgresql start
and the like ...
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.