Force bundle install to use https:// instead of git:// for GitHub-based gems

RubyGithubBundler

Ruby Problem Overview


I am trying to build a rails project and because the host I am working on doesn't have access to the Internet for the the git:// protocol (port 9418) I get errors like

Fetching git://github.com/pivotal/jasmine.git
fatal: unable to connect to github.com:
github.com[0: 192.30.252.130]: errno=Connection refused

when running bundle install.

The relevant line in the GemFile doesn't specify git:// as a protocol, it just points to GitHub as the source for the gem

gem 'jasmine', :github => 'pivotal/jasmine-gem'

What do I have to do to make bundler to use https:// rather than git:// for pulling gems from GitHub?

Edit:

Is there a way other than editing every affected line in the GemFile? I'd prefer to avoid any merging issues down the line if the project's GemFile is updated.

Ruby Solutions


Solution 1 - Ruby

Use bundle config github.https true

Solution 2 - Ruby

Git provides URL rewriting functionality using the url..insteadOf configuration option.

So to make all connections to github.com use https:// rather than git://

git config --global url."https://github.com".insteadOf git://github.com

The --global switch sets the config option for all git operations by the current user, so there are times where it may be too intrusive. But it does avoid changing the git config in the current project.

Solution 3 - Ruby

You can do:

gem 'jasmine', git: 'https://github.com/pivotal/jasmine-gem.git'

Solution 4 - Ruby

If you want this just for all the gems in one Gemfile you can add these lines at the top of the file:

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

Alternatively you can use bundle config github.https true. But this affects only your current environment.

This won't be necessary anymore with Bundler 2.0.

Solution 5 - Ruby

if you're deploying to heroku, you can just add BUNDLE_GITHUB__HTTPS (note the double underscore) as an environment variable and set it to true (in your heroku app's dashboard under the Settings tab in the Config Vars section). this will switch the protocol from git:// to https:// for all such requests.

Solution 6 - Ruby

You should be able to put a complete Git URL in your Gemfile. For example:

gem 'jasmine', :git => 'https://github.com/pivotal/jasmine-gem.git' 

Solution 7 - Ruby

If a solution that requires a special obscure setting to be performed on every installation you make for just a teeny weeny bit of syntactic sugar isn't a solution.

That's why I'm proposing this as an answer:

just use :https & report a security bug with bundler that the unencrypted protocol is default.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBellView Question on Stackoverflow
Solution 1 - RubySam Kah ChiinView Answer on Stackoverflow
Solution 2 - RubyBellView Answer on Stackoverflow
Solution 3 - RubyAgisView Answer on Stackoverflow
Solution 4 - RubymatthiasView Answer on Stackoverflow
Solution 5 - RubyclairityView Answer on Stackoverflow
Solution 6 - RubyJames FrostView Answer on Stackoverflow
Solution 7 - RubybbozoView Answer on Stackoverflow