環境
- MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
- CPU: 2.3 GHz Intel Core i5
- Memory: 16 GB 2133 MHz LPDDR3
- OS: High Sierra 10.13.5
概要
Ruby on Rails チュートリアルの開発環境構築
Ruby on Rails のバージョンは 5.1.4 をインストールする
インストール概要
- Xcode インストール
- Command Line Tool インストール
- Homebrew インストール
- rbenv インストール
- Ruby(rbenv) インストール
- Ruby on Rails
- node インストール
インストール詳細
Xcode インストール
- App Store にてインストール
Command Line Tool インストール
Xcode にてインストール
- Xcode を起動
- メニュー[Preferences…]を選択
- [General]ウィンドウの[Locations]をクリック
- [Command Line Tools]リストでバージョンを選択(Xcode 9.4.1 等)
コマンドラインからインストール
$ xcode-select --install
Homebrew インストール
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew -v
Homebrew 1.6.9
Homebrew/homebrew-core (git revision 3aeb; last commit 2018-07-04)
$ brew update
Already up-to-date.
rbenv インストール
$ brew install rbenv ruby-build
$ rvenv -v
rbenv 1.1.1
# 環境変数の設定
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
Ruby(rbenv)
# インストール可能な ruby バージョンの確認
$ rbenv install -l
Available versions:
1.8.5-p52
・
$ rbenv install 2.5.1
# デフォルト Ruby 設定
$ rbenv global 2.5.1
$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
Ruby on Rails インストール
Bundler インストール
$ gem install bundler --no-document
$ bundler -v
Bundler version 1.16.2
ruby on rails(v5.1.4) インストール
$ gem install rails -v 5.1.4
$ rails -v
Rails 5.1.4
node インストール
ExecJS::RuntimeError
対応のため、node をインストール
$ brew install nodebrew
$ nodebrew -v
nodebrew 1.0.0
Usage:
nodebrew help Show this message
・
# 環境変数の設定
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile
# 最新版をインストール
$ nodebrew install-binary latest
→エラー(※1)が発生する場合、以下のコマンドを実行
$ mkdir -p ~/.nodebrew/src
$ nodebrew ls
v10.6.0
current: none
$ nodebrew use v10.6.0
use v10.6.0
$ node -v
v10.6.0
エラー(※1)
$ nodebrew install-binary latest
Fetching: https://nodejs.org/dis t/v10.6.0/node-v10.6.0-darwin-x64.tar.gz
Warning: Failed to create the file
Warning: .nodebrew/src/v10.6.0/node-v10.6.0-darwin-x64.tar.gz:
Warning: No such file or directory
0.0%
curl: (23) Failed writing body (0 != 1058)
download failed: https://nodejs.org/dist/v10.6.0/node-v10.6.0-darwin-x64.tar.gz
RoRチュートリアル hello_app 作成
Gemfile編集後の bundle install
でエラー...
慌てず、bundle update
$ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "activesupport":
In snapshot (Gemfile.lock):
activesupport (= 5.1.6)
In Gemfile:
rails (= 5.1.4) was resolved to 5.1.4, which depends on
activesupport (= 5.1.4)
coffee-rails (= 4.2.2) was resolved to 4.2.2, which depends on
railties (>= 4.0.0) was resolved to 5.1.6, which depends on
activesupport (= 5.1.6)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
# 表示に従い bundle update
$ bundle update
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Using rake 12.3.1
・
Installing web-console 3.5.1 (was 3.6.2)
Bundle updated!
$ bundle install
Using rake 12.3.1
・
Using web-console 3.5.1
Bundle complete! 15 Gemfile dependencies, 64 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.