What is the easiest way to get Postgresql set up on OSX? - ruby-on-rails

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.

Related

How do I get 'psql' (from pgadmin4) installed on Fedora 34?

I am attempting to install 'pgadmin4' on a Fedora 34 VM (AWS AMI EC2), but it is not installing 'psql'
I ran these commands:
sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-fedora-repo-2-1.noarch.rpm
sudo yum install pgadmin4-desktop
and psql is no where to be found
I ran: sudo find / -type f -name psql, and nothing was found.
How do I get psql installed on Fedora 34?
I do not want to install the server / database. I just need 'psql' on the system. I do not need or want the web components.
I have lost about three hours with this, extremely frustrated.
I have searched and searched, tried a number of things.
It will be a miracle if I can get this working, if anyone has any ideas or has actually installed pgadmin4-desktop successfully or found a way to get psql onto a system (without installing the database software).
I just need the psql client.
Thank You,
Try
sudo yum install postgresql
pgadmin4-desktop sounds like GUI to me. If you need server it's in postgresql-server

So I installed postgresql and localhost port conflicting with ruby app?

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

ruby in linux: permanently "source .rvm/scripts/rvm"?

I'm new to Ruby on Rails and have just set it up in Ubuntu Linux following instructions I found here. Specifically,
As s.m. said, I uninstalled everything, then I opened another terminal session as a normal user and run:
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
then i run source /home/my-desktop-username/.rvm/scripts/rvm as a normal user NOT ROOT
then i run rvm requirements as a normal user. Then I copy the requirements and close the session, open a root session and install the requirements using sudo
Then I close the session and open a normal user session and run rvm install ruby-1.9.3-p125 if you run this command as root, it will say that rvm is not installed and will suggest that you install it using sudo apt-get install rvm Don't do that!
So basically I had two problems, the tutorials that i followed didn't say that i should run
source /home/my-desktop-username/.rvm/scripts/rvm and didn't say that I should not run rvm as root, s.m told me that. Thanks to everyone, especially to s.m
That works well, but I will have to remember to
source .rvm/scripts/rvm
every time I open a terminal to work with Ruby on Rails.
Is there a way to permanently tell Ubuntu to look in .rvm for all the Ruby stuff?
You need to add your
source .rvm/scripts/rvm
into your $HOME/.bashrc file; read the advanced bash scripting guide for more.

Setup Rails 3.1 and Postgresql on Snow Leopard

I have spent countless number of hours trying to setup PostgreSql on my Intel Mac.
I am able to install Rails and all but PostgreSql would not get installed on my Mac.
Anybody has any solution or any tutorial which I can follow to install it ??
P.S. I just started using Mac as my development machine. I have been using Windows before that !
Ok I had to do a little more research with a fresh mind and I am now able to solve the problem myself. Here is the solution :
Install Homebrew using this command :
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
Once installed write this in your terminal :
brew install postgres
If this is your first install ( which was the case with me ) than type this in terminal after the above step:
$ initdb /usr/local/var/postgres
To start the postgresql type this in terminal:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
After the above step type this :
ps auxwww | grep postgres
If the result of the above command in terminal looks like this than that means the postgresql is installed correctly :
26000 0.0 0.1 2445860 1556 ?? Ss 1:59AM 0:00.05 postgres: autovacuum launcher process
25999 0.0 0.0 2445728 512 ?? Ss 1:59AM 0:00.15 postgres: wal writer process
25998 0.0 0.0 2445728 912 ?? Ss 1:59AM 0:00.21 postgres: writer process
25996 0.0 0.1 2445728 2508 ?? S 1:59AM 0:00.15 /usr/local/Cellar/postgresql/9.0.4/bin/postgres -D /usr/local/var/postgres
26257 0.0 0.0 2435548 0 s000 R+ 2:19AM 0:00.00 grep postgres
Create a user and database:
createuser username
createdb -Ousername -Eutf8 databasename
To login to postgresql use this command:
psql -U username databasename
If you are using it with rails you can install the gem like this :
sudo env ARCHFLAGS="-arch x86_64" gem install --no-ri --no-rdoc pg
If you would like to stop the PostgreSQL service use this command :
pg_ctl -D /usr/local/var/postgres stop -s -m fast
Hope this will help others in saving the time of going through different resources to come with the solution like I did :)
Try using Cinderella. That will give you the whole stack (including MongoDB, Redis, and a whole bunch of other stuff) in one nice neat bundle in ~/Developer. You're better off using custom builds of all your development tools so that you don't have to worry about what version of anything comes with the system and what an upgrade might to do your OS.
References:
Cinderella on Github
Cinderella Homepage
A few other notes to add to your instructions:
There is a good post at Russ Brooks Blog on installation which validates much of what you have above.
There are a set of admin tools available at pgadmin.org which will allow you to browse your database through a simple GUI on the Mac
If you use the admin tools you should install the instrumentation pack with the following:
psql -d postgres < /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql
where the exact command obviously depends on the version of postgresql you are using.
If you are using postgres with rails and bundler then make sure the "pg" gem is in your gem file and run bundler with the following command immediately after you add it:
env ARCHFLAGS="-arch x86_64" bundle install
This will do the same as your 'gem install' command above. After you run it for the first time you no longer need to use the 'env ARCHFLAGS="-arch x86_64"' when you run bundler.
I had luck downloading and installing it straight from the site:
http://www.postgresql.org/download/macosx
I have used MacPorts for most of my server/low level program installations (PostgreSQL, MySQL, etc.). If you choose to go that route, you can then follow this blog post/tutorial on installing PostgreSQL via MacPorts onto your Mac. One thing to note on the PostgreSQL link: when following along, change the instances of 83 to 90. For example, you will see this in his steps:
sudo port install postgresql83 postgresql83-server
You can instead, type this to get the newest version of PostgreSQL
sudo port install postgresql90 postgresql90-server
I would also recommend grabbing a program such as Navicat for PostgreSQL Lite. It's free and nice to have to manage your local PostgreSQL DBs.
If you don't want to go with MacPorts, there's a similar alternative called HomeBrew that's quite popular ... I'm just too lazy to switch from MacPorts :).

Problem with Mongo DB using Mongoid Gem

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

Resources