LoginSignup
2
4

More than 3 years have passed since last update.

EC2デプロイ時、bundle installができずUndefined local variable or method `git_source' for Gemfileのエラーが出る件

Last updated at Posted at 2020-06-22

EC2デプロイ時に、サーバーにアプリをcloneするもbundle installでエラーが発生してハマりましたので、忘備録として載せておきます。

環境

Ruby 2.5.1
Rails 5.2.4.3

こちらの記事を参考にAWSにデプロイを進めている最中、bundle installを試みると以下のエラーが発生しました。

$ bundle install
-bash: bundle: コマンドが見つかりません

どうやら先にbundlerをインストールする必要があるみたいです。

$ gem install bundler
Fetching: bundler-2.1.4.gem (100%)
Successfully installed bundler-2.1.4
Parsing documentation for bundler-2.1.4
Installing ri documentation for bundler-2.1.4
Done installing documentation for bundler after 4 seconds
1 gem installed

bundlerがインストールできたようです!
bundle installしてみます。

$ bundle install
Traceback (most recent call last):
    2: from /home/hiroki/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
    1: from /home/hiroki/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/home/hiroki/.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)

違うエラーが出ています。
調べてみた結果、こちらのエラーはGemfile.lockに記載されているbundlerと実際にインストールされているbundlerののヴァージョンが違うということみたいです。
自分のGemfile.lockを確認したところ、bundler (>= 1.3.0)という記載があるのでバージョンを指定してインストールしてみます!

$ gem install bundler -v 1.3.0
Fetching: bundler-1.3.0.gem (100%)
Successfully installed bundler-1.3.0
Parsing documentation for bundler-1.3.0
Installing ri documentation for bundler-1.3.0
Done installing documentation for bundler after 1 seconds
1 gem installed

インストールできたので再度bundle installを行います。

$ bundle install
Undefined local variable or method `git_source' for Gemfile
        from /var/www/rails/Ticket-Rec/Gemfile:2

なんとまたエラーがでてしまいました。
こちらのエラーについて調べたところbundlerのバージョンが古いのでバージョンを上げると解決する場合があるとのことですが…
clone元は問題なく動いてたので、他に何か原因があるのではと思います。

解決

Gemfile.lock内に記載されているBUNDLED WITHのバージョンにbundlerを合わせると無事インストールできました。
Gemfile.lockの一番下に以下の記載があります。

Gemfile.lock
BUNDLED WITH
   1.17.1

再度bundlerのバージョンを指定してインストール

$ gem install bundler:1.17.1
Fetching: bundler-1.17.1.gem (100%)
Successfully installed bundler-1.17.1
Parsing documentation for bundler-1.17.1
Installing ri documentation for bundler-1.17.1
Done installing documentation for bundler after 3 seconds
1 gem installed

この後bundle installを実行すると無事成功しました!

参考

【画像付きで丁寧に解説】AWS(EC2)にRailsアプリをイチから上げる方法【その1〜ネットワーク,RDS環境設定編〜】

2
4
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
2
4