简体   繁体   English

如何在 Go 构建过程中更改 ~/.cache 目录

[英]How to change ~/.cache directory during the Go build process

Go build touches ~/.cache which is undesirable. Go build 触及 ~/.cache 这是不可取的。

How can I change the location of this directory?如何更改此目录的位置?

The cache defaults to the operating system-defined user cache directory but can be moved by setting $GOCACHE.缓存默认为操作系统定义的用户缓存目录,但可以通过设置 $GOCACHE 来移动。

Source: article from rsc来源: 来自rsc的文章

From the official documentation :官方文档

Build and test caching构建和测试缓存

The go command caches build outputs for reuse in future builds. go 命令缓存构建输出以在未来构建中重用。 The default location for cache data is a subdirectory named go-build in the standard user cache directory for the current operating system.缓存数据的默认位置是当前操作系统的标准用户缓存目录中名为 go-build 的子目录。 Setting the GOCACHE environment variable overrides this default, and running 'go env GOCACHE' prints the current cache directory.设置 GOCACHE 环境变量会覆盖此默认值,并且运行 'go env GOCACHE' 会打印当前缓存目录。

Note that the aforementioned go env GOCACHE command can be used to make sure that GOCACHE points to a desirable location before eg: building with go build .请注意,前面提到的go env GOCACHE命令可用于确保GOCACHE指向所需的位置,例如:使用go build Example:示例:

$ go env GOCACHE
/home/user/.cache/go-build
$ GOCACHE=/foo/bar
$ export GOCACHE
$ go env GOCACHE
/foo/bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM