Step by Step!

logicbaseのブログ

macOS Sierra に「Ruby on Rails」の環境を作ってみた

f:id:logicbase:20170121155030p:plain

MacmacOS Sierra)にRuby on Railsをインストールしたときの備忘録。

◆参考サイト
http://www.chi-kun.com/entry/2016/07/11/201623


MacのCommand Line ToolはDeveloperサイトからパッケージをDLしてインストールした
https://developer.apple.com/downloads/index.action

brew doctorでWarningがいっぱいでた
(対処方法を記載した↓のサイトが役立った)
http://www.task-notes.com/entry/20141223/1419324649

・インストールしたRubyのバージョンは、2.4.0
(後に、2.2.2をインストールすることになる・・・)

・インストールしたRubyのバージョン確認は、
$rbenv versions

railsをインストールする
$gem install rails --version "5.0.0" --no-rdoc --no-ri

ところが、
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
    
sudoをつければいいという記事があり、
$sudo gem install rails --version "5.0.0" --no-rdoc --no-ri

今度は、    
Fetching: activesupport-5.0.0.gem (100%)
ERROR:  Error installing rails:
    activesupport requires Ruby version >= 2.2.2.
    
Ruby 2.4.0じゃだめかと思い、2.2.2をインストールした。
(参考サイト:http://blog.integrityworks.co.jp/2016/09/12/1978/
$rbenv install 2.2.2

標準でRuby 2.2.2を設定
$rbenf gloval 2.2.2

再度、トライする
$sudo gem install rails --version "5.0.0" --no-rdoc --no-ri

出来たっぽいのでバージョン確認
$rails -v
Rails 5.0.0


環境づくり成功!




・つづけて、Railsアプリをつくってみる!
$mkdir rails

$cd rails

$rails new sample

Errno::EACCES: Permission denied @ dir_s_mkdir -
/Users/higuchiakio/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-16/2.2.0-static/byebug-9.0.6
An error occurred while installing byebug (9.0.6), and Bundler cannot continue.
Make sure that `gem install byebug -v '9.0.6'` succeeds before bundling.
         run  bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`

エラーだ・・・
Permissionのエラーみたいなので、sudoを付けてみた。

$sudo rails new sample


ちょっと進んだが、まだエラーがでる・・・
Bundle complete! 15 Gemfile dependencies, 62 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
         run  bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`


bundle installが行われないようにいったんスキップして再度実行するという記事があったので、skip-bundleのオプションをつけてみた
(参考サイト:http://syaka-syaka.blogspot.jp/2014/08/rails-new.html

$sudo rails new sample --skip-bundle

おっ!正常終了だ!


$cd sample

$rails s
エラーだ・・・
There was an error while trying to write to `/Users/higuchiakio/rails/sample/Gemfile.lock`. It is likely that you need to grant write permissions for that path.

またPermissionなんとかとでているので
$sudo rails s

=> Booting Puma
=> Rails 5.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.2.2-p95), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Started GET "/" for ::1 at 2017-01-20 20:14:09 +0900

うまくいったぞ!

http://localhost:3000にアクセスする!

f:id:logicbase:20170121155030p:plain


めでたくRailsのWelcomeメッセージ画面が表示されたのでありました(^^)v