Install Private GitHub Repos With NPM

How to install and uninstall a private Node package stored on GitHub.

GitHubNPMNode.js

Installing a Node package via a private repo is useful when your code can’t be made public. To install, you’ll need an SSH key set up on your account and made available to git.

Installing

bash
npm install git+ssh://git@github.com:<username-or-org>/<repo-name>.git

This command will attempt to pull the package using your SSH token. You need to replace:

  • <username-or-org> — With your GitHub username or organisation.
  • <repo-name> — With the name of your repo.

For this command to work, your package must be a valid Node package. That means it needs a valid package.json.

Uninstalling

bash
npm uninstall <package-name>

Where <package-name> is the name of your package, as defined in your package.json. This will remove the package from your package.json dependencies and the package-lock.json.