Mac cross-compile to Linux/arm64 error: "build cache is required, but could not be located: GOCACHE is not an absolute path"



I'm running GoLand 2021.2.2 on MacOS and trying to cross-compile to linux/amd64 (native darwin/amd64 builds work fine) and receiving the error regarding GOCACHE in the post's title above. Running "go env" in my shell shows GOCACHE set correctly with an absolute path. I have the following run configuration:

I've tried it with and without setting GOCACHE explicity in the run configuration with the same resulting error. I feel like I'm probably missing something obvious. My searches haven't found others with a similar problem -- and, oddly, not even many pages with info about cross-compiling in GoLand (perhaps because it's straightforward for most folks?). Hoping someone out there can help.




For cross-compiling, you just need to set up environment variables in run configuration settings as you did, especially GOOS and GOARCH, GOCACHE is not required. The message about GOCACHE comes from the compiler itself, not from the IDE. What version of Go are you using?

First off, please, try to do the same thing via terminal, e.g. GOOS=linux GOARCH=arm64 go build -o hello-world ./... and, after that, you can make sure that it compiles for arm64 by executing file hello-world command. Does it compile correctly?

By the way, if you have to use GOCACHE, you should specify it without quotes: GOCACHE=/Users/


Thanks for your response, Daniil. I should have mentioned that I'm using Go 1.17 darwin/amd64. Cross-compilation works fine for both amd64 and arm64 in the shell:

mk@tonks:~/work/svn_migrate> GOOS=linux GOARCH=amd64 go build -o foobar ./...
mk@tonks:~/work/svn_migrate> file foobar
foobar: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=5UmO3zpZEfSQUyZLFSGQ/Fq21pXIBhFvHmZD29eqh/-4DzcLc3rtnTzmrBLwAi/kXUSvclj_9N6Ly3Z6rkL, not stripped

I removed the explicit set of GOCACHE, but it still fails.

Any other ideas? Thanks!



Could you please provide a full compilation output from the IDE (after pressing the run button inside the Run tool window)? If you can upload the IDE logs to and provide its ID, it would be great as well.


Thanks again, Daniil. The log upload ID is 2021_09_22_uiPKNyJ5gmpjJix4

GOROOT=/usr/local/opt/go/libexec #gosetup
GOPATH=/Users/mk/go #gosetup
/usr/local/opt/go/libexec/bin/go build -o /Users/mk/work/svn_migrate/build/Local_linux_amd64_linux svn_migrate #gosetup
build cache is required, but could not be located: GOCACHE is not defined and $HOME is not defined

Compilation finished with exit code 1

Ah ha! It turns out you must actually define HOME in the run configuration:

I should have taken the error message to heart. I'm just surprised that the environment does not have HOME defined. I suspect this has something to do with how the build process is run (e.g. it may not be getting my shell's normal environment). At any rate, that was unexpected. Could be worth adding this to the docs or making a fix to require setting HOME.

Daniil, thanks for your help!


Does it help if you click on the icon on Environment field and select Include system environment variables option? If not, where did you specify $HOME variable (.zshrc, .bash_login, etc.)?


Ha! You're right. Somewhere along the way I unchecked the system env vars option. In retrospect, I think what happened is that that configuration began as a remote build config on a linux box and was gradually changed to a local cross-compile. 

Classic user error. As I said in my original post, it was likely me missing something obvious. Thanks again for your patience and help, Daniil, and sorry I couldn't see it sooner.


Please sign in to leave a comment.