5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLをMacへインストールしてRails newする

Posted at

概要

ポートフォリオ作成時、今までずっとMySQLに慣れ親しんでいたので、
PostgreSQLとやらに挑戦しようと思い、とりあえずインストール方法〜新規Railsアプリ作成までをまとめてみました!

条件

  • macOS Mojave(ver 10.14.5)

手順

  • Homebrewを使用してPostgreSQLをインストール
  • PostgreSQLの起動 / 起動確認 / 停止方法
  • データベース一覧を表示
  • Ruby on Railsのバージョンを変更
  • アプリケーションを新しく作成
  • GitHubに登録し、ローカルリポジトリを作成
  • リモートリポジトリを作成

Homebrewを使用してPostgreSQLをインストール

postgresqlをインストール

brew install postgresql

バージョン確認

psql -V

インストール場所を確認

which psql

PostgreSQLの起動 / 起動確認 / 停止方法

起動

brew services start postgresql

起動状況の確認

brew services list

停止

brew services stop postgresql

データベース一覧を表示

データベース一覧を表示

                                            List of databases
         Name          |     Owner      | Encoding | Collate | Ctype |         Access privileges         
-----------------------+----------------+----------+---------+-------+-----------------------------------
 postgres              | ************** | UTF8     | C       | C     | 
 test-app_development  | ************** | UTF8     | C       | C     | 
 test-app_test         | ************** | UTF8     | C       | C     | 
 template0             | ************** | UTF8     | C       | C     | =c/**************                +
                       |                |          |         |       | **************=CTc/**************
 template1             | ************** | UTF8     | C       | C     | =c/**************                +
                       |                |          |         |       | **************=CTc/**************

Ruby on Railsのバージョンを変更

cd ~ #ホームディレクトリに移動
gem install rails --version="5.2.4.1" #今回はversion="5.2.4.1"を使用
rbenv rehash #gemの変更を反映

アプリケーションを新しく作成

cd
rails new test-app -d postgresql #rails newコマンドを実行
cd test-app #test-appディレクトリに移動
rails db:create #データベースを作成

GitHubに登録し、ローカルリポジトリを作成

GItHub Desktop から test-app のローカルリポジトリを作成。
左上の「Current Repository」→「Add」→「Add Existing Repository」を選択。

※「Add Repository」がクリックできない場合、事前に該当するアプリケーションのディレクトリで以下の作業を行う。

cd ~/git-app
git init #rails のバージョンによっては rails new 時に git init がされないケースがあるため

その後コミット。

リモートリポジトリを作成

[Publish repository]ボタンをクリックすると GitHub のリモートリポジトリが作成できる。
GitHub の Your repositories の欄に作成したアプリがあれば上手くいっている。

サーバー起動

rails s

できた!制作スタート!

Image from Gyazo

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?