①ポスグレのインストール
$ brew update
$ brew install postgresql
②ポスグレを起動するとエラーがでる
$ postgresql
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
③エラーの解消
コンフィグファイルの設定をして下さいと書いている。
ホームディレクトリに戻る
$ cd ~
ホームディレクトリに設定用のファイル".bash_profile"、".bashrc"があるか下記コマンドで確認
$ ls -a
ない場合は、下記コマンドで作る
$ touch ~/.bash_profile
$ touch ~/.bashrc
再度確認すると、ある。
$ ls -a
.bash_profileと、.bashrcの説明は下記URLを参照
https://qiita.com/takutoki/items/021b804b9957fe65e093
先ほど作った、~/.bash_profileに環境変数を設定してパスを通す
④下記コマンドで、ターミナルをコマンドモードに切り替る
$ vi .bash_profile
⑤コマンドモードに入ったらiを押してインサートに切り替える
i
⑥下記、環境変数を追記する
export PGDATA='/usr/local/var/postgres'
⑦保存してコマンドモードを終了する
キーボード【ESC】
↓
下記コマンドを入力
:wq
⑧下記コマンドを入力して変更を反映させる
$ source .bash_profile
⑨下記コマンドにて、postgresqlが立ち上げれば設定完了
$ postgres
⑩データベースをポスグレに指定し、好きなバージョンも指定し、Railsプロジェクトを作成して終了
$ rails _5.1.7_ new アプリ名 -d postgresql