Installing PostgreSQL on Ubuntu for Ruby on Rails
Here are the steps I've followed:
Install PostgreSQL and development package
$ sudo apt-get install postgresql
$ sudo apt-get install libpq-dev
Set up a user that is the same as my Ubuntu log-in
$ sudo su postgres -c psql
postgres=# CREATE ROLE <username> SUPERUSER LOGIN;
postgres=# \q
Modify Gemfile
# Remove gem 'sqlite3'
gem 'pg'
Modify database.yml
in app directory
development:
adapter: postgresql
encoding: unicode
database: appname_development
pool: 5
timeout: 5000
username: <username>
password:
test:
adapter: postgresql
encoding: unicode
database: appname_test
pool: 5
timeout: 5000
username: <username>
password:
Run bundle install
$ bundle install
Create databases and migrations
$ rake db:create:all
$ rake db:migrate
Here are the sources I used to help:
http://mrfrosti.com/2011/11/postgresql-for-ruby-on-rails-on-ubuntu/
http://railscasts.com/episodes/342-migrating-to-postgresql
https://devcenter.heroku.com/articles/local-postgresql
Getting PostgreSQL set up on Ubuntu bash running on Windows
Found the solution to these problems.
Issue #1 - 'pg' gem not installing
Execute the following in bash:
- sudo apt-get install libpq-dev
- gem install pg
- bundle install
Issue #2 - postgresql cannot start without crashing
Uninstall all versions on PSQL on computer and reinstall one. The failed installation and the second version were sharing their data folder and caused errors with the installation I was using.
PgAdmin on Windows 10 with Postgres when installed via Bash on Ubuntu on Windows
Here's what I did to connect Postgres DB installed in WSL Ubuntu from Windows pgAdmin.
- Launch Ubuntu in Windows.
- Start postgres in Ubuntu terminal:
sudo service postgresql start
- Download the latest pgAdmin and install in Windows.
- Launch pgAdmin, a new tab in browser opens; click on Add New Server link.
- In the popup Create - Server window in the browser:
- General tab: I set Name to localhost
- Connection tab: I set Host name/address to localhost, set Password to postgres, which is the default, click on
Save password?
- I save the setting, leaving the rest of the fields as is
- That's it, I can see the DB created in Postgres immediately.
tips for installing postgres for a rails project on a linux box
This article from the Rails wiki should contain the information you are looking for.
I suggest you to install the pg
GEM:
gem install pg
Also, Slicehost published a really interesting collection of article about using and configuring PostgreSQL on Ubuntu: http://articles.slicehost.com/postgresql
Related Topics
What Does &: Mean in Ruby, Is It a Block Mixed with a Symbol
How to Improve Jruby Load Time
Rvm Does Not Install Ruby 1.9.2 on Snow Leopard: 'Error Running 'Make '
Windows: Rails: Error Installing Bson_Ext
Bundle Install Issue with Libv8 and Rails
How to Send Message Using Gmail API with Ruby Google API Client
How to Customize the Table Builder Plugin for a Week Calendar
How to Declare a String with Both Single and Double Quotes in Yaml
How to Escape #{ from String Interpolation
Chaining Methods Using Symbol#To_Proc Shorthand in Ruby
Ruby 1.9: Regular Expressions with Unknown Input Encoding
Where Should My Non-Model/Non-Controller Code Live
Combine Array of Array into All Possible Combinations, Forward Only, in Ruby