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

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

问题描述

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

解决方案

以下是我遵循的步骤:



安装PostgreSQL和开发包

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

设置一个用户与我的Ubuntu登录相同

  $ sudo su postgres -c psql 
postgres =#CREATE ROLE<用户名> SUPERUSER LOGIN;
postgres =#\q

修改Gemfile

 #删除gem'sqlite3'
gem'pg'
database.yml

 开发:
适配器:postgresql
编码:unicode
数据库:appname_development
池:5
超时:5000美元b $ b用户名:<用户名>
密码:

测试:
适配器:postgresql
编码:unicode
数据库:appname_test
池:5
超时: 5000
用户名:<用户名>
密码:

运行捆绑安装

  $ bundle install 

创建数据库和迁移

  $ rake db:create:all 
$ rake db :迁移

以下是我用来提供帮助的来源:

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


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?

解决方案

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

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

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