# go: 获取构建缓存时出错: 无法打开 /root/.cache/go-build/log.txt: 权限被拒绝

- **ID:** `go/build-cache-invalid`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

构建缓存目录被其他用户拥有或权限不正确，阻止了写入操作。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **Change ownership of the build cache directory to the current user.** (95% 成功率)
   ```
   Run 'sudo chown -R $USER:$USER /root/.cache/go-build' (adjust path if needed).
   ```
2. **Set GOCACHE to a writable directory.** (90% 成功率)
   ```
   Run 'export GOCACHE=$HOME/.cache/go-build' and ensure the directory exists: 'mkdir -p $GOCACHE'.
   ```

## 无效尝试

- **Running 'go clean -cache' to clear cache.** — The command fails because it cannot access the cache to remove it. (80% 失败率)
- **Setting GOCACHE to a different path without creating it.** — Go won't automatically create the directory; it must exist with proper permissions. (70% 失败率)
