When deploying EC2, bundle install cannot be performed and an error of Undefined local variable or method `git_source'for Gemfile appears.

When deploying EC2, I cloned the app to the server, but an error occurred in bundle install and I was addicted to it, so I will post it as a memorandum.

environment

Ruby 2.5.1 Rails 5.2.4.3

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

$ bundle install
-bash: bundle:Command not found

Apparently 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! 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'm getting a different error. As a result of investigating, this error seems to be that the version of bundler described in Gemfile.lock is different from the version of bundler actually installed. When I checked my Gemfile.lock, it says 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

Now that it's installed, 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 investigated this error, it is said that the version of bundler is old, so it may be solved by increasing the version ... The clone source worked fine, so I suspect there is something else.

Solution

I matched the bundler with the version of BUNDLED WITH described in Gemfile.lock and it was installed successfully. You can find the following at the bottom of Gemfile.lock.

Gemfile.lock


BUNDLED WITH
   1.17.1

Install by specifying the bundler version again

$ 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 this, I ran bundle install and it was successful!

reference

[Carefully explained with images] How to upload Rails application to AWS (EC2) from scratch [Part 1 ~ Network, RDS environment setting ~]

Recommended Posts

When deploying EC2, bundle install cannot be performed and an error of Undefined local variable or method `git_source'for Gemfile appears.
I get an error with bundle install and puma cannot be installed.
Undefined local variable or method error in partial template collection option