0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on Rails [学習記録-第0章-]

Last updated at Posted at 2019-06-17

これからRuby on Railsをプログラムする上で必要なことを都度纏めていく。
基本的に、学習内容の備忘録として使用します。

参考サイト:rubyのインストール方法 Mac編

概要

Ruby on Railsを始める前に、以下のものをインストールする。

  1. Command Line Tool
  2. Homebrewのインストール
  3. rbenvとruby-buildインストール
  4. Ruby ver.2.5.1のインストール
  5. MySQLのインストール
  6. bundlerのインストール
  7. Ruby on Railsのインストール

Command Line Tool

まず最初HomebrewをインストールするためにCommand Line Toolをインストール。
アクセス時にApple IDとパスワードを要求される。
自分のMacのOSのバージョンに合わせたものをインストール。

コマンドラインツール

Homebrewのインストール

下記コードはHomebrewをインストールするためのコマンド。cdコマンドでホームディレクトリに移動してから実行。途中で要求されるパスワードは自分のMacのパスワード。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Homebrewがインストールされているか確認
$ brew -v 
$ brew update

Macのバージョンが10.11.1以上の場合、ターミナルから以下のコマンドを実施して権限を変更。

$ sudo chown -R 'whoami':admin /usr/local/bin

rbenvとruby-buildのインストール

Homebrew使って、rbenv(アールベンブ)とruby-build(ルビー・ビルド)という2種類のアプリケーションをインストール。

$ brew install rbenv ruby-build

rbenvとruby-buildは、Rubyのバージョンを管理する際に組み合わせて使用。
ruby-buildによってRubyの様々なバージョンをインストール可能。
rbenvを使用することでrubyのバージョンを切り替える。
開発環境によってはRubyの特定のバージョンでなければエラーが出る。

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

rbenvのパスを通す。パスを通すことでrbenvをどのディレクトリからも使用。

$ source ~/.bash_profile

.bash_profileの読み込み。書き込んだ設定を読み込み、有効にする。

readlineのinstall

$ brew install readline

Ruby ver.2.5.1のインストール

Macに最初から入っているRubyは、rbenvでのバージョン管理ができない。

$ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)"
$ rbenv install 2.5.1

利用するRubyのバージョンを決める

$ rbenv rehash #リハッシュ
$ rbenv global 2.5.1 #指定したバージョンでインストール
$ ruby -v #バージョンの確認

MySQLのインストール

$ $ brew install mysql@5.6 #インストール
$ mkdir ~/Library/LaunchAgents #自動起動の設定
$ ln -sfv /usr/local/opt/mysql\@5.6/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql\@5.6.plist #PCを起動すると同時にMySQLも自動で起動
# mysqlのコマンドを実行できるようにする
$ echo 'export PATH="/usr/local/opt/mysql@5.6/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
# mysqlのコマンドが打てるか確認する
$ which mysql
# 以下のように表示されれば成功
/usr/local/opt/mysql@5.6/bin/mysql

bundlerのインストール

$ gem install bundler #bundlerとはgemのバージョン管理などをしてくれるgem
  • gem(ジェム)とは、Rubyを便利に扱うためのアプリケーションの総称。ターミナルからそれぞれのgemが持つコマンドを実行するという形で使用。

Ruby on Railsのインストール

$ gem install rails --version='5.2.2.1'
$ rbenv rehash
$ rails -v
  • rbenv rehashコマンドは、そのバージョンで利用しているgemのコマンドを使えるようにするために必要なコマンドです。gemコマンドでgemをインストールしたときは、rbenv rehashコマンドを実行するのを忘れないようにしましょう。
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?