# go: failed to lock module cache: /home/user/go/pkg/mod/cache/download/lock: permission denied

- **ID:** `go/module-cache-lock-error`
- **Domain:** go
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The user does not have write permission to the module cache lock file, often due to running Go as a different user or in a restricted environment.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.11 | active | — | — |
| 1.12 | active | — | — |
| 1.13 | active | — | — |
| 1.14 | active | — | — |
| 1.15 | active | — | — |
| 1.16 | active | — | — |
| 1.17 | active | — | — |
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |
| 1.23 | active | — | — |

## Workarounds

1. **Change ownership of the module cache to the current user** (90% success)
   ```
   sudo chown -R $(whoami) $(go env GOMODCACHE)
   ```
2. **Set GOMODCACHE to a writable directory** (85% success)
   ```
   export GOMODCACHE=/tmp/gomodcache && go mod download
   ```

## Dead Ends

- **Running 'sudo go build' to bypass permissions** — Running Go as root can cause ownership issues and security risks; may also not resolve if the cache is owned by another user. (60% fail)
- **Deleting the lock file manually** — The lock file is managed by Go; deletion may cause race conditions or corruption. (80% fail)
