在 Ubuntu 上为 Ruby on Rails 安装 PostgreSQL [英] Installing PostgreSQL on Ubuntu for Ruby on Rails

查看:28
本文介绍了在 Ubuntu 上为 Ruby on Rails 安装 PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 Ubuntu 12.04 中通过 RVM 安装了 Ruby on Rails.默认数据库是在 SQLite3 中设置的,但为了推送到 Heroku,我想切换到 PostgreSQL.我怎样才能做到这一点?

I currently have Ruby on Rails installed via RVM in Ubuntu 12.04. The default database is set up in SQLite3, but I'd like to switch to PostgreSQL for the purposes of pushing to Heroku. How can I accomplish this?

推荐答案

以下是我遵循的步骤:

安装 PostgreSQL 和开发包

$ sudo apt-get install postgresql
$ sudo apt-get install libpq-dev

设置一个和我的Ubuntu登录一样的用户

$ sudo su postgres -c psql
postgres=# CREATE ROLE <username> SUPERUSER LOGIN;
postgres=# q

修改 Gemfile

# Remove gem 'sqlite3'
gem 'pg'

修改应用目录下的database.yml

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:

运行捆绑安装

$ bundle install

创建数据库和迁移

$ rake db:create:all
$ rake db:migrate

以下是我用来帮助的来源:
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

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

这篇关于在 Ubuntu 上为 Ruby on Rails 安装 PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆