Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

go

Go build touches ~/.cache which is undesirable.

How can I change the location of this directory?

like image 232
Flying Jay Avatar asked Feb 26 '18 07:02

Flying Jay


1 Answers

From the official documentation:

Build and test caching

The go command caches build outputs for reuse in future builds. The default location for cache data is a subdirectory named go-build in the standard user cache directory for the current operating system. Setting the GOCACHE environment variable overrides this default, and running 'go env GOCACHE' prints the current cache directory.

Note that the aforementioned go env GOCACHE command can be used to make sure that GOCACHE points to a desirable location before e.g.: building with go build. Example:

$ go env GOCACHE
/home/user/.cache/go-build
$ GOCACHE=/foo/bar
$ export GOCACHE
$ go env GOCACHE
/foo/bar
like image 140
kelvin Avatar answered Sep 19 '22 18:09

kelvin