[Ruby] Unable to do bundle install when EC2 deploy and get error of Undefined local variable or method `git_source’ for Gemfile

1 minute read

When I deployed EC2, I cloned the application on the server, but I got hooked because an error occurred in bundle install, so I will post it as a memorandum.


Ruby 2.5.1 Rails

While deploying to AWS referring to the article of here, the following error occurred while trying to install bundle.

$ bundle install
- bash: bundle: command not found

It seems that you need to install bundler first.

$ 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

It seems that bundler has been installed! I will try 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)

I am getting a different error. As a result of checking, this error seems to be that the version of the bundler described in Gemfile.lock is different from the version of the bundler actually installed. When I checked my Gemfile.lock, there is a description of bundler (>= 1.3.0), so I will specify the version and install it!

$ 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

I was able to install it, so do bundle install again.

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

I got an error again. When I checked this error, the version of bundler is old, so it may be solved by raising the version… The clone source worked without any problems, so I think there may be some other cause.


I installed it successfully by matching the bundler with the version of BUNDLED WITH described in Gemfile.lock. At the bottom of Gemfile.lock you will find the following:



Specify the bundler version again and install

$ 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

After that, I executed bundle install and it was successful!


[Carefully explained with image] How to raise Rails app from AWS (EC2) [No. 1 ~ Network, RDS environment setting ~]