11
9

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でgit cloneなり新規作成なりしたプロジェクトをセットアップする手順とそのための環境構築

Last updated at Posted at 2014-10-14

Rubyプロジェクトディレクトリの準備手順

rbenvで始めるRubyプロジェクト。

Rubyの用意

rbenvを入れておくこと。「前提」>「rbenvを入れておく」参照。

# rbenv versions # インストール済みRuby一覧
# rbenv install -l # インストール可能なRuby一覧
# rbenv install 2.0.0-p481 # インストール
rbenv local 2.0.0-p481 # ディレクトリで利用するRubyの指定

gemの用意

gem をインストール

bundle install # 
# 次のコマンドと同じ挙動とする。「前提」の設定がまだの場合は次のコマンドで
# bundle install  --path=vendor/bundle --binstubs=vendor/bin 

gemfileの作り方

1からプロジェクトを作成する場合にGemfileを生成するには

bundle init

以上でRubyプロジェクトを動かす(着手する)準備は完了。

以下は上記手順でいろいろうまく動かせるようにするための事前準備手順。

前提

rbenvを入れておく

brew install readline ruby-build rbenv
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
. ~/.bash_profile #環境再読み込み
rbenv global system #標準で使うRubyはシステムデフォルトのものに

bundlerを入れておく

インストールしたRubyを有効にしたディレクトリで実行。インストール済みの場合不要。インストール自動化は「やっておくと便利」>「Bundlerのインストールを自動化」参照。

gem install bundler

bundlerの設定でGemがディレクトリローカルにインストールされるようにしておく

gemがグローバルにインストールされて他の環境を汚したりしないよう、いつも無意識にbundle installするだけでディレクトリローカルにインストールされるようにしておく。

bundle config --global path 'vendor/bundle' #gemをローカルインストール
bundle config --global bin 'vendor/bin' # binを作りbundle execを省略可に

#個別に設定したい場合は場合はbundlerをオプション付きで実行。
bundle install --path=vendor/bundle --binstubs=vendor/bin 

やっておくと便利

Bundlerのインストールを自動化

Rubyインストールと同時にbundlerをインストールさせることが出来る。
rbenv install したときに 一緒に bundler をインストールする - そんなこと覚えてない
(http://blog.eiel.info/blog/2013/04/12/rbenv-install-after-install-bundler/)

rbenv-binstubsプラグイン

rbenvのプラグイン。無くても動くが、bundle installしたgemを実行させる時に bundle exec [command] を直接[command]と入力できるようになる。

$ git clone git://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs

rbenv-gem-rehashプラグイン

rbenvのプラグイン。無くても動くが、gem install / bundle installするたびに必要になるrbenv rehashが自動化される。

$ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
11
9
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
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?