Go "fork/exec /tmp: permission denied" - Fix in CI
go test builds a test binary into a temp directory and execs it. When /tmp is mounted noexec or otherwise restricted, the exec is denied and the test cannot run.
What this error means
A test fails with fork/exec /tmp/go-buildNNN/b001/x.test: permission denied. The temp directory is mounted noexec or lacks execute permission.
go
fork/exec /tmp/go-build123456/b001/app.test: permission deniedCommon causes
/tmp mounted noexec
The temp filesystem disallows execution, so the freshly built test binary cannot run.
Restricted TMPDIR permissions
The temp directory lacks execute permission for the build user.
How to fix it
Use an exec-allowed TMPDIR
- Point TMPDIR at a directory that permits execution.
.github/workflows/ci.yml
- run: |
mkdir -p "$RUNNER_TEMP/gotmp"
TMPDIR="$RUNNER_TEMP/gotmp" go test ./...Remount with exec if you control the host
- Remount the temp filesystem allowing execution.
shell
sudo mount -o remount,exec /tmpHow to prevent it
- Set TMPDIR to an exec-allowed path in CI.
- Avoid noexec mounts for directories Go builds into.
- Verify TMPDIR permissions early in the job.
Related guides
Go "panic: test timed out" - Fix in CIFix Go "panic: test timed out after Xm" in CI - a test exceeded the -timeout budget. Fix the hang or raise th…
Go "too many open files" (ulimit) - Fix in CIFix Go build/test "too many open files" in CI - the process hit the file-descriptor ulimit. Raise the limit o…
Go "package fmt is not in std" (broken GOROOT) - Fix in CIFix Go "package fmt is not in std" in CI - even stdlib imports fail, meaning GOROOT is wrong or the install i…