To use and publish private packages on GitHub Packages, you need to set up proper authentication. This guide explains how to create a GitHub Personal Access Token (PAT) and configure your environment.
- Go to your GitHub account settings
- Navigate to Developer settings → Personal access tokens → Tokens (classic)
- Click Generate new token
- Give your token a descriptive name (e.g., "Chaingraph Packages")
- Set the expiration as needed (you can choose "No expiration" for long-term use)
- Select the following scopes:
repo(full control of private repositories)read:packages(download packages)write:packages(publish packages)delete:packages(optional, for package management)
- Click Generate token
- Important: Copy the token immediately and store it securely. You won't be able to see it again!
Create or edit an .npmrc file in your project root:
@badaitech:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
Then set the GITHUB_TOKEN environment variable:
# Linux/macOS
export GITHUB_TOKEN=your_github_pat_here
# Windows (Command Prompt)
set GITHUB_TOKEN=your_github_pat_here
# Windows (PowerShell)
$env:GITHUB_TOKEN="your_github_pat_here"Edit your global ~/.npmrc file:
@badaitech:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=your_github_pat_here
Replace your_github_pat_here with your actual GitHub personal access token.
Test your authentication by running:
npm whoami --registry=https://npm.pkg.github.comIf successful, it should display your GitHub username.
For GitHub Actions:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
registry-url: 'https://npm.pkg.github.com'
scope: '@badaitech'
- name: Install dependencies
run: npm install
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}For other CI systems, set the GITHUB_TOKEN or NODE_AUTH_TOKEN environment variable with your PAT.