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.
- Log in with your Github account and visit the tokens page
- Add a meaningful name, set your expiration, and grant
repo
access - Copy the token for use later
To successfully run bundle install
locally, you need to either add:
- A token to your local repo with
bundle config --local github.com <token>
- Confirm with
cat .bundle/config
and see your token - NOTE: Be careful using this. Some teams keep a shared/committed
.bundle/config
file
- Confirm with
- A token to your global bundle config with
bundle config --global github.com <token>
- Confirm with
cat ~/.bundle/config
and see your token - NOTE: Be careful using this if you store your
~/.bundle/config
file in a github repo
- Confirm with
- To your environment with an environment variable
export BUNDLE_GITHUB__COM=<token>
- Confirm with
env | grep BUNDLE_GITHUB__COM
and see your token - Protip: Use mise-en-place or direnv to securely set these locally per-folder/repo
- Confirm with
- 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
- Some repos have
./bundle/config
checked into the git repository so local + CI/CD uses the same bundle config settings. You can use your global config, unless... - Some people (like me) commit their global
~/.bundle/config
into a public dotfiles repo so I keep my bundle configs the same across machines. Don't store secrets in here if you do this - Using environment variables is recommended if you can't use the bundle config file. Use direnv, mise-en-place, or another tool for managing environment variables per-folder/repo if you need to use the same environment variable with different values in different folders
- Some repos have
Worked a treat, thanks! 🏆