1
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.

bundle update と bundle install の違いについて

Posted at

はじめに

ふと、bundle installをした時に、下記のエラーが出た
Running bundle update will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.
調べたらbundle update をしていないことが原因だったのだが、そもそも"install"と"update"の違いがまだきちんと理解できていないことに気づいてこの記事をまとめようと思った。

bundlerについて

そもそもbundlerについてもう少し詳しく述べておくと、「gemの依存関係のものを一括で扱ってくれる」ものである。つまり一つの機能を用いようとする時に、いくつものgemをインストールしなければならない時があるかもしれないが、bundlerを用いると依存関係を持っている複数のものを一括でインストールしてくれるというものだ。
これは確かに便利なのかもしれない!

gemfile と gemfile.lock

gemfileはgemをインストールするための設計図と呼ばれ、gemfile.lockは実際にインストールした結果図と例えても良い。
つまり、gemfileに書かれているgemのみならず一括でインストールしたものを、gemfile.lockにまとめて記述されていることとなる。
これは知らなかった、gemfile.lockにそんな役割があるとは。

bundle install

これを踏まえてbundle installについて考えていく。
bundle installはgemfile.lockに記載されている内容を踏まえて、gemをインストールしていく。ちなみに、この時にgemfile.lockには記載されていないがgemに記載されているgemなどは、インストールした後にgemfile.lockも更新する

bundle update

bundle updateはgemfileを元にgemのインストールを行う。そしてそのあとに、gemfile.lockを更新する。

まとめ

つまり、bundle updateはgemのバージョンを更新する時に用いる。bundle installはgemfile.lockを更新しないため、gemfileに新しくgemを記述した時に使用する。
また、本番環境でbundle updateはgemのバージョンのズレが起きやすいため使用せず、bundle installは新しい環境などで用いていくのが良い。

1
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
1
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?