LoginSignup
5
5

More than 5 years have passed since last update.

Ruby on Rails環境をMacで構築してみる

Last updated at Posted at 2016-08-16

インターン中に手持ちのMacでRoRのアプリケーションを動かしたくなりMacで環境構築してみた話。
Macbook Air(Mid 2013)の環境は以下のとおり。

  • Core i5 1.4GHz
  • OS X El Capitan 10.11.6

rbenvのインストール

Homebrewから以下のコマンドでrbenvをインストールする。rbenvはRubyのバージョンを管理してくれるものらしい。

$ brew update
$ brew install rbenv ruby-build

Rubyのインストール

以下のコマンドをうっていく。2016年8月16日時点で最新は2.3.1のようなのでこれを入れてみる。

$ rbenv install -l #バージョンのリストがでてくる
$ rbenv install 2.3.1
$ rbenv rehash
$ rbenv global 2.3.1
$ rbenv -v #ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]とでるはず

Railsのインストール

必要最低限なgemとRailsコマンドもインストール。

$ gem install bundler
$ gem install rails
$ rbenv rehash

あとはアプリケーションのbundle installでインストールすればおーけーだったが、pgというコマンド?でインストールがこける。エラーメッセージから以下のコマンドをたたいた。このときpostgresqlが必要らしいのでいっしょにインストール。

$ brew install postgresql
$ gem install pg -v '0.18.4'
$ bundle install

これでうまくいった。あとはdb:createなどをしたいところだがこれもこける。こんな感じのエラー。

PG::ConnectionBad (could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?

これは調べるとpostgresqlがシステムで立ち上がっていないためらしい。ので以下のコマンドをたたく。そうしたらデータベースの初期化がめでたくできるようになる。

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
$ bundle exec rails db:create db:migrate db:seed

あとはサーバーを立てればlocalhostでアクセスできるようになった。めでたしめでたし。

$ bundle exec rails server

参考

以下のサイトが参考になりました。ありがとうございました。

5
5
2

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
5