在Ubuntu Linux上更改GOCACHE默认文件夹

I must put all the files GO creates inside the structure of GO, not scattered. While changing GOPATH and GOROOT, I noticed the build folder on ~/.cache/go-build.

This SO thread didn't help at all, not either the article it links. It doesn't seems to deal directly with that. How can I change it?

Edit: the problem isn't how to find the GOCACHE, which I already know that can be viewed by go env GOCACHE, but how can I change that folder.

I've tried to add to ~/ .bashrc: export GOCACHE=$HOME/path/to/folder, and now when I use go env GOCACHE, it points to the new folder but still tries to send files to ~/.cache/go-build. The log file is now returning the following error:

go: disabling cache (/home/<me>/.cache/go-build) due to initialization failure: mkdir /home/<me>/.cache/go-build: permission denied

The error shown

go: disabling cache (/home/<me>/.cache/go-build) due to initialization failure: mkdir /home/<me>/.cache/go-build: permission denied

Is because the directory /home/<me>/.cache/go-build does not exist and permissions to create a new directory aren't there. This shouldn't happen, it seems like some unknown factor in your build process is clobbering the GOCACHE settings

Do you literally have a user called <me>? That's quite unusual and ill advised, as <> are shell meta characters

As for setting the path, see https://github.com/golang/go/blob/master/src/cmd/go/internal/cache/default.go and https://golang.org/pkg/os/#UserCacheDir

If GOCACHE env variable is set then it uses that. If not it uses os.UserCacheDir which is usually $HOME/.cache but can be overridden, see the docs

The simple answer is to set the GOCACHE env variable to be inside your Go containment area

Just to clarify. Go compiler and tools run inside another environment.

This other environment has variables set inside it, which Go will honour

On Linux systems, this environment is usually the bash shell. In the bash shell to set the GOPATH the command "export GOPATH=$HOME/go" is often used, to set up a GOPATH to a folder called go in the home directory of the current user. To set the GOCACHE set the variable in the environment you are using and Go will pick it up