# 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](https://help.sonatype.com/en/create-a-go-repository.html "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:

1. Store your credentials in `~/.netrc` on Linux and macOS or `%HOME%\_netrc` on 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

2. On Linux and macOS only, set the file permissions to retrieve the credentials. Run:

```
   chmod 600 ~/.netrc
   ```
   
3. 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=*`

4. Skip the authentication step if you are using the anonymous access.

### Example:

```bash
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=* 
```
