Defining Terms

Go Tools With Tmpfs

My desktop computer runs Linux and has an SSD and plenty of ram, so I’ve mounted /tmp to a tmpfs RAM disk, as others have suggested. This is nice because it makes things faster and cuts down on writes to the SSD, but it causes problems with some of the go tools.

Both go run and gotour compile binaries to /tmp and try to run them from there. When /tmp is a tmpfs volume, you will get errors like this:

1
2
$ go run hello.go
fork/exec /tmp/go-build995932098/command-line-arguments/_obj/a.out: permission denied

One solution is to set the tmp directory to a location that’s not in a ramdisk, just in the shell you’re using to run go. In a bash shell, you can do that with these commands:

1
2
$ mkdir ~/tmp
$ export TMPDIR=~/tmp/

Then the go commands will work correctly:

1
2
$ go run hello.go
hello, world

You will have to export TMPDIR each time you open a new shell in which you want to use the problematic go tools.