Railsの導入
こちらのサイトが参考になります。
http://exrecord.net/how-to-construct-ruby-on-rails-environment-in-ubuntu
PostgreSQLの導入
以下を参考にしてインストールします。
- https://www.postgresql.org/download/linux/ubuntu/ (公式サイト)
- https://weblabo.oscasierra.net/postgresql10-ubuntu1604-install/
まず、/etc/apt/sources.list.d/pgdg.list
を作成し、以下を追記します。
/etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
次にレポジトリを追加し、インストールします。
# レポジトリを追加
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
# インストール
$ sudo apt-get install postgresql-client-10 postgresql-client-common postgresql-common postgresql-server-dev-10 postgresql-10 pgdg-keyring
# インストールを確認
$ dpkg -l | grep postgres
ii pgdg-keyring 2018.1 all keyring for apt.postgresql.org
ii postgresql-10 10.5-2.pgdg16.04+1 amd64 object-relational SQL database, version 10 server
ii postgresql-client-10 10.5-2.pgdg16.04+1 amd64 front-end programs for PostgreSQL 10
ii postgresql-client-common 195.pgdg16.04+1 all manager for multiple PostgreSQL client versions
ii postgresql-common 195.pgdg16.04+1 all PostgreSQL database-cluster manager
ii postgresql-server-dev-10 10.5-2.pgdg16.04+1 amd64 development files for PostgreSQL 10 server-side programming
さらに、パスワードなしでログイン出来るように設定します。まず、pg_hba.confを開いてください。
$ sudo vi /etc/postgresql/10/main/pg_hba.conf
そして、最下部にある METHOD を以下のように全て trust に書き換えてください。
/etc/postgresql/10/main/pg_hba.conf
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
これでインストールは完了です。
以下のコマンドで起動出来ます。
$ sudo systemctl start postgresql