Photo by Ivan Vranić on Unsplash

Bundler 2系しか入っていなくて既存アプリがbundle installできなかった…

Tatsuya Tobioka
Ruffnote
Published in
5 min readFeb 6, 2019

--

12月末時点では問題なく動いていたアプリが、1月末にサーバーインスタンスが作り直されたタイミングで起動しなくなった…という事象が発生しました。

設定は何も変えてないないのに一体なぜ…と思っていろいろ調べてみるとbundle installが失敗していることがわかりました。

サーバーに入って調べてみると、Bundlerの2.0.1しか入っていないせいでした。

Rubyの状態

Rubyは2.5.1でした。

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
$ which ruby
~/.rbenv/shims/ruby
$ rbenv version
2.5.1 (set by /home/username/.rbenv/version)

Bundlerの状態

Bundlerは2.0.1が入っており、単体ではちゃんと動きます。

$ bundle -v
Bundler version 2.0.1
$ gem list bundle*** LOCAL GEMS ***bundler (2.0.1)$ bundle init
Writing new Gemfile to /home/username/Gemfile

Bundler 1系のプロジェクトで動かすと…

GemNotFoundExceptionになります。

# Gemfile
# frozen_string_literal: true
source "https://rubygems.org"git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }# Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
PLATFORMS
ruby
DEPENDENCIESBUNDLED WITH
1.17.1
$ bundle install
Traceback (most recent call last):
2: from /home/username/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
1: from /home/username/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/home/username/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

解決策

Bundlerの1系を入れれば解消です。

$ gem install bundler -v 1.17.3
Fetching: bundler-1.17.3.gem (100%)
Successfully installed bundler-1.17.3
Parsing documentation for bundler-1.17.3
Installing ri documentation for bundler-1.17.3
Done installing documentation for bundler after 4 seconds
1 gem installed
$ gem list bundle*** LOCAL GEMS ***bundler (2.0.1, 1.17.3)$ bundle install
The Gemfile specifies no dependencies
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

ちなみに NotFound状態で gem install bunlder を叩くと何度も2系がインストールされ続けます…。

$ gem install bundler
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Done installing documentation for bundler after 3 seconds
1 gem installed

また、 gem uninstall bundlerで1.17.3を消すとエラーが無事(?)再現しました。
めでたしめでたし…?

Bundler 2系は .lockファイルを見て切り替えるようなので、切り替える先のBundlerが見つからずNotFoundエラーになるということでしょう。

最初原因不明で焦りましたが、年初にBundler 2系がリリースされたのでそれが起因で発生したものでした。

バージョン指定せずに`gem install bundler`で環境構築しているようなサーバーがもしあれば、ご注意ください。

--

--