26
24

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.

弊社後輩のためのBundlerの説明

Last updated at Posted at 2015-04-23

なお、環境はMacです。

bundlerってのは、「同梱」みたいな意味のライブラリで、Gemfileに書いてあるライブラリをプロジェクトと関連づける役割をする。
各ライブラリのバージョンも、Gemfile.lockに書かれているバージョンに固定される。

bundle install

bundle install

は、文字通りインストール。
Gemfile.lockを見ながら、既に存在するライブラリのバージョンはそのままで、ないものはインストールされる。

bundle update

bundle update

は、文字通りアップデート。後ろになにも書かないと、Gemfile(.lockじゃないやつ)で
バージョン固定されていないライブラリは全部バージョンアップしようとする。

bundle update rails

って書くと、railsとそれが依存するライブラリのみアップデートしようとする。
その際に、Gemfile.lockも上書きされる。

私の場合は、bundle update hogehogeした後に必ずテストを行い、通ったらgitでcommitする。
乱暴にbundle updateのみを行うことは、ほぼない。

bundle exec

bundle exec hogehoge

は、そのプロジェクト内で使ってるライブラリのバージョンを使って操作する。
例えば、

gem install rails

ってやっていると、今だと4.2.1が入ってしまうから、
bundle execつけずにrails sなどを実行すると、4.2.1のrailsで実行される。

しかし、既存のプロジェクトみたいにプロジェクト内のGemfileにgem rails, '3.2.19'って書いてあるところで

bundle exec rails s

って書くと、3.2.19のrailsで実行される。

複数のプロジェクトで異なるバージョンのライブラリを使っていたりするときには、必ずbundle execを付けるといい。
railsの場合はプロジェクト内で

bin/rails s

とか、binディレクトリができてて、それを使うとよしなにしてくれるようにはなったけど。

オマケ: Alias

.bash_profileなど、ログインした際に読み込まれるファイルに以下を書いておくと便利。

.bash_profile
# Alias
alias be='bundle exec'
alias bi='bundle install'
alias bu='bundle update'

こうすることで、be middlemanbe rails sなどと書けるようになる。

26
24
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
26
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?