Can’t execute go run or go mod tidy with this error message.

Case

There might be not $HOME environment.

In my case, it occurred when I tried to use runcmd of cloud-init.

echo $HOME

// nothing is displayed

Solution

Must set $HOME environment before execute go run.

export HOME=/hoo