Ruby-on-Rails on Ubuntu 8.04
Every time I build an Ubuntu machine I have to figure out all over again how to get it to work - so this time I’ll write the steps down!
Install the packages: postgresql, rake, ruby, rubygems, rcov, git-core
Update the RubgyGems distribution by running
sudo gem update –system
If you run gem now you’ll get the nasty looking error:
/usr/bin/gem:10:Warning: Gem::manage_gems is deprecated and will be removed on or after March 2009
/usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError)
You need to edit /usr/bin/gem and add an extra require:
require ‘rubygems/gem_runner’
Install the Postgres driver:
sudo gem install postgres-pr
You’ll need to change where Postgres writes it’s socket file, if you leave things unchanged you’ll see the error:
No such file or directory - /tmp/.s.PGSQL.5432
when attempting to connect to the database.
Edit /etc/postgresql/8.3/main/postgresql.conf and alter the unix_socket_directory parameter:
unix_socket_directory = ‘/tmp’
Restart Postgres using the init script /etc/init.d/postgresql-8.3
You should be able to leave your pg_hba.conf file unchanged - it should already look like:
# Database administrative login by UNIX sockets
local all postgres ident sameuser
# “local” is for Unix domain socket connections only
local all all ident sameuser
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
You need to create a database user, and give that user a password and create a database. As the postgres user:
createuser -lqs db_username
createdb -O db_username db_name
psql -c “alter user db_username with password ‘db_password’;”
In the last command above make sure you don’t miss the ‘;’ character, if you miss it the statement isn’t actually executed, you should see the command confirmed with ALTER ROLE.
In you Rails application database.yml you need to specify the database name, database username and password and the host (even if it’s localhost)
development:
adapter: postgresql
encoding: unicode
database: db_name
host: localhost
username: db_username
password: db_password
November 2nd, 2008 at 6:20 pm
Thank you very much for this post! I have the exact same problem since friday, I found your post and fix it
Regards.
December 26th, 2008 at 1:15 am
Thanks! It worked perfectly for Ubuntu 8.10 (Ibex). (I’m also using Sequel instead of ActiveRecord.)