Skip to content
jshacks.dev
Packages

Authenticate to GitHub Packages

Install private packages from GitHub Packages with a scoped registry line and a token read from GITHUB_TOKEN in .npmrc. Token needs read:packages scope.

1 min read
Summarize in AI

GitHub Packages serves npm packages from its own registry at npm.pkg.github.com. Route your organization's scope there, and authenticate with a token that has the read:packages permission.

.npmrcText
@acme:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
Shell
npm config get @acme:registry
Text
https://npm.pkg.github.com

Only packages under the @acme scope go to GitHub; everything else still comes from npmjs.org. Then npm install @acme/ui works as usual once GITHUB_TOKEN is set in the environment. In GitHub Actions, the built-in secrets.GITHUB_TOKEN can do this for packages in the same organization when the workflow has packages: read. The setup is described in working with the npm registry.

A classic personal access token with read:packages is the simplest for local use. Keep it in your shell profile or a secret manager, never in the .npmrc itself.

The package scope must match the owner of the repository, in lowercase. A mismatch makes the publish fail with a permissions error.

Also inSecurity
Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.