douruduan8812 2018-12-07 12:08
浏览 454
已采纳

在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

  • 写回答

1条回答 默认 最新

  • douzhushen_9776 2018-12-07 13:24
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置