Skip to content

Instantly share code, notes, and snippets.

@jaydorsey
Created May 25, 2022 01:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydorsey/7810580dac0a289581e7ba8168b843e8 to your computer and use it in GitHub Desktop.
Save jaydorsey/7810580dac0a289581e7ba8168b843e8 to your computer and use it in GitHub Desktop.
Setting up a github/bundle token for privately hosted repos

If your Gemfile has a privately hosted package referenced similar to this:

gem 'sekret', git: 'https://github.com/my-private-group/sekret.git', branch: 'main'

You may see a prompt when running bundle install, or other bundler commands, to enter your github username & password.

To resolve this, you need to generate a token and add it to your system.

Generating a token

  1. Log in with your Github account and visit the tokens page
  2. Add a meaningful name, set your expiration, and grant repo access
  3. Copy the token for use later

Setting the token

To successfully run bundle install locally, you need to either add:

  1. A token to your local repo with bundle config --local github.com <token>
  • Confirm with cat .bundle/config and see your token
  1. A token to your global bundle config with bundle config --global github.com <token>
  • Confirm with cat ~/.bundle/config and see your token
  1. To your environment with an environment variable export BUNDLE_GITHUB__COM=<token>
  • Confirm with env | grep BUNDLE_GITHUB__COM and see your token

Caveats

  • For CI/CD you probably don't want to use a personal token. Use a "bot" account (Github suggests this) with limited access
  • Each engineer should/could use their own token locally
  • You can also use dotenv or anything else
  • There are reasons to use each of the above ways of setting a token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment