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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题