Monday, December 7, 2015

How to run Rails with PostgreSQL on openSUSE Leap 42.1

I wrote about how to run Rails with PostgreSQL on openSUSE 12.3 before. Things have changed since then. While Rails, PostgreSQL, and openSUSE are still excellent choices, new versions have been released. This warrants an update. So here is how to get a development environment of Rails with PostgreSQL running on the latest and greatest openSUSE Leap 42.1.

Install PostgreSQL:

    sudo zypper install postgresql-server postgresql-devel

Start the database server:

    sudo systemctl start postgresql

Enable server to be started on boot:

    sudo systemctl enable postgresql

Switch to the postgres user to set up the database:

    sudo su -l postgres

Create database user:

   createuser -d USERNAME

Return to your normal user, exchange the database driver in the Gemfile from sqlite3 to pg and run

   bundle install

Change the configuration of the database driver to something like:
  default: &default
    adapter: postgresql
    username: cs

    <<: *default
    database: APPNAME_development

    <<: *default
    database: APPNAME_test

    <<: *default
    database: APPNAME_production
Create the databases:

    rake db:create
    rake db:migrate
    rake db:migrate RAILS_ENV=test

That's it.