Install Go tools from private repositories using GitHub PAT
Installing private Go tools from GitHub can be tricky due to authentication issues. Here’s a step-by-step guide to help you seamlessly install private Go modules.
Prerequisites
A GitHub personal access token (PAT) with
repo
scope.Go installed on your machine (version 1.22.3 or higher).
Step 1: Configure .netrc
First, we need to configure the .netrc
file to store GitHub credentials. This file allows Git to authenticate using stored credentials without prompting for username and password.
Step 2: Set Environment Variables
Set necessary environment variables for Git and Go.
Step 3: Configure Go to Bypass the Proxy for Private Repositories
Tell Go to bypass the module proxy for private repositories by setting the GOPRIVATE
environment variable.
Step 4: Configure Git to Use Personal Access Token
Instead of relying on the .netrc
file, you can configure Git to directly use the personal access token.
Step 5: Disable Go Proxy Temporarily
Sometimes, the Go module proxy can cause issues when accessing private repositories. Disable it temporarily for the installation.
Step 6: Install the Go Module
Now you can install the Go module using the go install
command.
Example Workflow
Here’s the full set of commands combined into a workflow:
Troubleshooting Tips
Check Token Permissions: Ensure your GitHub token has the necessary
repo
permissions.Verify Repository Path: Double-check the repository path and module version.
Network Issues: Ensure your network allows access to GitHub.
Conclusion
By following these steps, you should be able to install private Go modules from GitHub without encountering authentication issues. This approach helps automate the authentication process and ensures a smoother development workflow.
Last updated