LoginSignup
7
3

More than 5 years have passed since last update.

MacでRuby on Rails環境構築(備忘録)

Last updated at Posted at 2018-06-30

詳しくまとめてくださってる人がいたのでこちらをもとに環境構築
https://qiita.com/narikei/items/cd029911597cdc71c516

homebrewをインストール

http://brew.sh/index_ja.html

Rubyのインストール

rbenvをインストール

$ brew install rbenv
$ brew install ruby-build # 
$ rbenv version
2.5.1 (set by ******)

ruby-buildってなに?って人は以下参照
http://ruby.studio-kingdom.com/rbenv/ruby_build/

bash_profileに追記

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
$ source ~/.bash_profile

Rubyをインストール

$ rbenv install --list #インストールバージョンを確認
$ rbenv install 2.5.1 

※20180630現在の最新

rbenvのバージョンを切り替える

$ rbenv global 2.5.1
$ rbenv rehash
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
$ gem -v
2.7.6

bundlerインストール

$ gem install bundler
$ bundle -v
Bundler version 1.16.2

MySQL編

MySQLをインストール

$ brew install mysql

MySQL起動

$ mysql.server start
Starting MySQL
SUCCESS! 

Rails編

好きなワークスペースを作成

$ mkdir ~/workspace
$ cd ~/workspace

bundle init

$ bundle init
Writing new Gemfile to /Users/*****/workspace/Gemfile

できあがったGemfileのRailsのコメントアウトを外す

Gemfile
# A sample Gemfile
source "https://rubygems.org"

gem "rails"

Railsインストール

$ bundle install --path=vendor/bundle
Fetching gem metadata from https://rubygems.org/...........

Railsアプリケーション作成

$ bundle exec rails new . -d mysql

mysqlを指定。
オプションを指定しない場合はsqliteがデフォルトで設定される。
GemfileがConflictしていますが Y で上書き

(新しいGemを追加する場合)先ほどと同じようにライブラリインストール

$ bundle install --path=vendor/bundle
Fetching gem metadata from https://rubygems.org/...........

Railsアプリケーション起動

$ bundle exec rails s
PC-10214:workspace a13161$ bundle exec rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

Rails 5.2ではPumaがデフォルトで起動するようで

おわり

http://localhost:3000/ へアクセスしてみましょう!

7
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
7
3