How to change the Go AWS SDK default download directory in Linux. Getting no space left on device error

huangapple go评论76阅读模式
英文:

How to change the Go AWS SDK default download directory in Linux. Getting no space left on device error

问题

我正在尝试下载Go AWS SDK,但是我的根目录空间不多。
我已经挂载了另一个设备(/mnt/device2/),那里有15GB的可用空间。

当我运行命令 go get -u github.com/aws/aws-sdk-go/... 时,我收到以下错误信息:

> go build github.com/aws/aws-sdk-go/service/macie2: mkdir
> /tmp/go-build3967698646/b570/: no space left on device

我想将默认的下载目录从 /tmp/ 更改为 /mnt/device2/

这样做是否可能?

英文:

I am trying to download the Go AWS SDK but I don't have much space in my root.
I have mounted another device (/mnt/device2/) where I have 15 GB space available.

When I run the command go get -u github.com/aws/aws-sdk-go/... I get the error

> go build github.com/aws/aws-sdk-go/service/macie2: mkdir
> /tmp/go-build3967698646/b570/: no space left on device

I want to change the default download directory from /tmp/ to /mnt/device2/.

Is it possible to do so?

答案1

得分: 1

根据这里的文档:

当检出一个新的包时,go get 命令会在目标目录 GOPATH/src/<import-path> 下创建文件夹。如果 GOPATH 包含多个条目,go get 会使用第一个条目。更多详情请参考:go help gopath

文档进一步描述了每个标志,但似乎没有允许你更改下载目录的选项。

这在某种程度上是有道理的,因为它简化了操作,并且如果你主要使用模块,更改 GOPATH 应该是相当无缝的。

我的建议是,如果你正在使用 Go 模块,只需更改 GOPATH 环境变量,将其指向你新挂载的存储设备。这样做将会:

  1. 在构建或执行 go mod tidy 时,重新下载所有依赖项。
  2. 如果你使用远程工具,并将此服务器用作开发环境,你需要为每个项目运行 go mod tidy,以防止代码编辑器和集成开发环境报错。
  3. 如果你选择删除旧的 GOPATH 目录,请确保新的 GOPATH/binPATH 中,并且你需要重新安装可能已安装在那里的任何二进制文件。
英文:

Going by the documentation here

> When checking out a new package, get creates the target directory
> GOPATH/src/<import-path>. If the GOPATH contains multiple entries, get
> uses the first one. For more details see: 'go help gopath'.

Further it describes each flag and none of them seem to allow you to change the download directory.

It kinda makes sense in that it removes complexity and the fact that if you're using modules primarily - changing GOPATH should be pretty seemless.

My suggestion, provided you're using go modules, would be to just change your GOPATH env variable to point to your newly mounted storage device. This will:

  1. Re-Download all your dependencies in all your golang projects when you build or go mod tidy them
  2. If you use remote tools and used this server as you dev env - you would need to run go mod tidy for each project to prevent code editors and IDEs from screaming error at you.
  3. If you choose to delete the old GOPATH directory - make sure your new GOPATH/bin is in PATH - and you would need to re-install any binaries you may have installed there.

huangapple
  • 本文由 发表于 2021年12月24日 14:26:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/70470147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定