Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save willgarcia/7347306870779bfa664e to your computer and use it in GitHub Desktop.
Save willgarcia/7347306870779bfa664e to your computer and use it in GitHub Desktop.

Description

When using Homebrew (http://brew.sh) and searching formulas or pull requests you may get the dreaded error message: Github API Rate limit exceeded

Let's fix that! (yeah!)


Short version

Create a new Personal Token in your Github Account Settings (Sidebar: Applications) and then copy the Token. In the Terminal, use export HOMEBREW_GITHUB_API_TOKEN=YOURAPITOKENWITHFUNKYNUMBERSHERE (change that to your API Token) or add that to your .bash_profile and then do source .bash_profile.

Step 1 - Create a Personal Access Token for Homebrew

  1. Login to your Github Account or create one if you don't have one yet.
  2. In the top menu to the right, click the tools icon (Account Settings).
  3. Click on “Applications” in the sidebar (to the left).
  4. In the box with the title “Personal Access Tokens”, press the “Create new token” button.
  5. In the next box (Create a new Personal Access Token) set the name of your Token (i used homebrew but you can use anything you want). Press “Create Token”.
  6. When done, you will see your token we just created in the “Personal Access Tokens” box. Copy the Token by select the token or click the copy icon to the right of the Token text.
  7. The Token text should look something like this: 9927d2878ffa105fc5236c762f2fd7zfd28b841d (not a real token, just an example)

IMPORTANT! Remember To Keep The Token Safe As It Works As A “Password” For Your Github Account.

Step 2 - Set the Github API Token for Homebrew in the Terminal

  1. Fire up your Terminal.app (or iTerm.app)
  2. Use the command export HOMEBREW_GITHUB_API_TOKEN=9927d2878ffa105fc5236c762f2fd7zfd28b841d (but use your own API Token, and not the fake example one that don't work) and press enter.
  3. It's now set, however, instead of repating this every session, let's add this to our .bash_profile (if you don't know about this, see this link.)
  4. Open your .bash_profile in your favorite text editor (in this case, we use Nano in the Terminal). Make sure that you are in your Home directory (if unsure, use cd $HOME and press enter).
  5. Add the exact same line as in step 2. Press ctrl + o (to save) and then ctrl + x (to quit Nano)
  6. In your Terminal, do the command source .bash_profile (loads the changes in the .bash_profile file to the active session)
  7. Well, that's it!

###Helpful links


Tags: homebrew, brew, github api, token, api token, terminal, mac os x

@perty
Copy link

perty commented Feb 6, 2020

It is "Developer Settings" now, not "Applications".

@mgkuhn
Copy link

mgkuhn commented Jun 7, 2021

Which “scopes” does this token need to have selected? Any at all? Otherwise, shouldn't I unselect all scopes (least privilege)?

@perty
Copy link

perty commented Jun 7, 2021 via email

@mgkuhn
Copy link

mgkuhn commented Jun 7, 2021

No scope seems to work fine for me so far. After all, Homebrew doesn't actually need any of the rights available, as this use of the token seems all just about enabling GitHub to identify users, to be able to rate-limit abusers, not to enable for Homebrew any particular API functionality on your own repos or user data.

@perty
Copy link

perty commented Jun 8, 2021 via email

@hughdbrown
Copy link

I'd have thought that read:packages Download packages from GitHub Package Registry was the desired permission.

@mgkuhn
Copy link

mgkuhn commented Jun 19, 2021

@hughdbrown: I think read:packages is only needed to enable your application to download your own private packages, i.e. not for homebrew, where everything is public.

@Bunkermaster
Copy link

You should NOT allow home-brew access to any of your scopes. The token is only necessary for you to access the GitHub API on a non anonymous provision. Giving home-brew any access to your GitHub ressources would be a major security breach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment