Configure Go with Nexus
Configure Go with Nexus
Configure your Go client to connect to and authenticate to a Nexus Go repository. Before you begin, create a Go repository in Nexus. Refer to Create a Go Repository for more details.
The Go toolchain uses environment variables such as GOPROXY, GONOSUMDB, and GOAUTH to define how modules are resolved, how checksums are managed and how credentials are supplied.
Prerequisites:
- Install Go
Take the following steps to configure Go with Nexus:
- Store your credentials in
~/.netrcon Linux and macOS or%HOME%\_netrcon Windows.
machine <HOST>
login <USERNAME>
password <PASSWORD>
EOF
Where,
<HOST>- Your Nexus Instance<USERNAME>- Your username or user token name code<PASSWORD>- Your password or user token pass code
- On Linux and macOS only, set the file permissions to retrieve the credentials. Run:
chmod 600 ~/.netrc
Add the netrc file, enter your repository URL and the checksum repository URL (optional).
go env -w GOAUTH=netrc go env -w GOPROXY=<NEXUS_REPOSITORY_URL> go env -w GOSUMDB='sum.golang.org<NEXUS_RAW_URL>'Where,
<NEXUS_REPOSITORY_URL>- Your Nexus repository URL<NEXUS_RAW_URL>- Your Nexus raw (proxy) URL for checksum cache.
Note
If you do not wish to cache the checksum database, use GONOSUMDB=*
- Skip the authentication step if you are using the anonymous access.
Example:
go mod init github.com/go-sample-project
go mod tidy
go env
nano ~/.netrc
'''
machine example.nexus.com
login admin
password admin123
'''
chmod 600 ~/.netrc # for Linux and macOS only
go env -w GOPROXY=example.nexus.com/repository/go-proxy/
go env -w GOSUMDB='sum.golang.org example.nexus.com/repository/raw-proxy/'
# for no checksum
go env -w GONOSUMDB=*