Fix GoLand 'Make' run configurations not finding Go

"Makefile support" plugin configuration dialog in GoLand
Image credits: Victor Kropp

In a GoLand make run config, tasks defined in the Makefile correctly find the go binary on macOS, but not on Ubuntu, causing errors like this one :

1
2
3
client/test.wasm: client/main.go
	# Building WASM
	GOARCH=wasm GOOS=js go build -o client/test.wasm client/main.go
1
2
3
/usr/bin/make -f (un chemin)/Makefile client/test.wasm
/bin/sh: 1: go: not found
make: *** [client/test.wasm] Error 127

Let’s fix this…

The diagnosing process

Let’s check how the same command behaves when run on the command line:

1
GOARCH=wasm GOOS=js go build -o client/test.wasm client/main.go`

No error, compile works normally. So it has to be an issue with GoLand or the make plugin. Let’s check the Makefile:

1
2
3
4
client/test.wasm: client/main.go
	# "${PATH}"
	# Building WASM
	GOARCH=wasm GOOS=js go build -o client/test.wasm client/main.go
1
2
3
# Building WASM
make: *** [client/test.wasm] Error 127
# "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

So, at least on that version, the run configuration ignores the PATH variable environment variable. This is easy to fix.

The fix

A simple fix would just add the Go binaries directory to the Make tasks (i.e. modify the Makefile) but, since this is not needed on other environments, better just tell GoLand to add the path to the run configuration instead of the Makefile.

  1. Run echo $PATH on the command line.
  2. Modify the relevant run configuration.
  3. In the run configuration dialog, modify the Environment variables field
  4. Add one row for the PATH environment variable, copied and pasted from the output of the first step.
  5. Click Apply and close the dialog.

make oddities

As usual, make has its own peculiar charm: it requires the name of the variable to be within braces to be recognized, instead of just using $PATH.

Trying to modify the PATH variable by expanding it with something like $PATH:/usr/local/go/bin or ${PATH}:/usr/local/go/bin instead of copy/pasting the value does not work :

  • with the former, make receives the evaluated result of $P, then concatenates the ATH string to that result, causing binaries in all directories except /usr/local/go/bin to become unavailable.
  • with the latter, make detects a self-referencing variable, and cancels the task.