Will I be able to install a private package?
nekky
HOBBYOP

7 months ago

I have two repositories in my GitHub organization. One is a package/module/library, and the other is a full-fledged project that uses this library.

Question: Can Railway install a dependency in the form of this private package? Using git+[https://github.com//.git](https://github.com//.git)

I should clarify that Railway has access to all of the organization's repositories.

$10 Bounty

2 Replies

nekky
HOBBYOP

7 months ago

N/A


loganbek
FREE

7 months ago

Yes, here's how to get it working:

  1. Generate a GitHub Personal Access Token (PAT)
    Go to https://github.com/settings/tokens → Generate a token with:

    • repo scope (for private repos)

    • read:packages if you're using GitHub Packages

  2. In Railway → Variables, add:

    GH_TOKEN=ghp_yourlongtokenhere
  3. In your package.json, add the private package like this:

    "dependencies": { 
      "my-private-lib": "git+https://$GH_TOKEN@github.com/my-org/my-private-lib.git" 
    }
  4. Use .npmrc (optional but safer)
    You can also create a .npmrc file in your root with:

    //github.com/:_authToken=${GH_TOKEN}

    Then in package.json:

    "dependencies": {
      "my-private-lib": "git+https://github.com/my-org/my-private-lib.git"
     }

Remember:

  • Do not hardcode the token in package.json; always use Railway env variables or .npmrc.

  • If using Yarn, same idea applies, just make sure .npmrc exists and GH_TOKEN is set in Railway.


Loading...