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
Related
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
I'm trying to load a Rails 3.2 project on my Macbook and I'm having difficulty. I installed Postgres 9.1.4 via brew. After putting /usr/local/bin in the front of my $PATH, I can now get into Postgres from the command line via psql.
However, in my Rails project, when I run:
rake db:create:all
I get the following error:
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"?
Well that file indeed does not exist. Yet I can access the database via the command line with psql.
Why is it looking in that area, and what can I do to make it look in the proper place (whatever that is) for Postgres?
This is depressingly common on OS X systems for users of Homebrew and Postgres.app.
What happens is that your Rails 'Pg' gem gets compiled against the old PostgreSQL version Apple pre-installs on some Mac OS X versions, rather than the version you installed yourself. This happens because the PATH has the Apple version of pg_config on it before the version you installed.
Any of these alternatives will work:
Recompile the Pg gem to use the correct libpq by setting your PATH so that the right pg_config is on it before compiling (best option);
Set an explicit socket directory when you connect with host: /tmp, or with psql etc -h /tmp/;
Use TCP/IP: host: localhost, psql -h localhost, etc;
You can find more detail here:
PostgreSQL Mountain Lion socket issue
Check your database.yml file. Probably a bad configuration
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?
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.
Wondering if anyone could help me? I've recently switched over to Mac and trying to set up my Rails environment. I want to set up Postgresql as my database since I used it with my Windows development. The trouble is, there are a number of different ways to set it up and I just wanted to know which would be the best and error free.
I have homebrew installed too, I see it is available to download through there but has anyone had any experience through this route?
Cheers
Postgres.app is the easiest way to run PostgreSQL on the Mac
Almost same answer but using homebrew:
brew install postgresql
Get mac ports from http://www.macports.org/
sudo port install postgresql84; sudo port install postgresql84-server
You may need to tweak pg_hba.conf to allow connections from ::1 (IPv6 localhost).
Alternately, from source:
ARCH=x86_64 CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"
./configure --prefix=/usr/local/pgsql --with-libxml --with-libxslt --with-openssl
make
sudo make install
sudo su postgres -c '/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/'
sudo su postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /var/log/pgsql/postgresql.log start'
sudo chown -R postgres /usr/local/pgsql/
You could use cinderella to get the whole PostgreSQL, MongoDB, Ruby, ... stack in one go. The initial install takes awhile but it puts everything in ~/Developer so it is easy to keep track of and easy to clean up.
Just get the PostgreSQL OSX installer, provided by EnterpriseDB.
You might consider http://postgresapp.com/.
It claims to be "the easiest way to run PostgreSQL on the Mac" and so far it has been true for me.
I'm developing on Ubuntu, I have installed the mongoid gem, and when I run the rails server, I get this error
/home/username/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/connection.rb:518:in `connect': Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)
I remembered using a command like brew install but I am pretty clueless. Am I missing something? Thanks in advance!
You need to have MongoDB installed, too. Since you're on Ubuntu, try this:
sudo apt-get install mongodb
If you saw any brew commands in any instructions you were reading, those were likely for Homebrew on Mac OS X, not for Ubuntu.
other possibility
you didnt start the server(which should auto-start usually)
mongod also has this weirdness
try to run sudo mongod in a foreground process
and the messages should tell you how to recover