Search code examples
goland

Why running go env in GoLand's terminal is different from system terminal


The output in GoLand's terminal: this is goland go env

The output of go env in the OS terminal: this is system go env


Solution

  • GoLand manages some of the environment variables and settings and overrides what's configured in the system so that it can create a reproducible environment between running code in the builtin terminal or when using the editor itself.

    From what I can see in the images, I see that there are some differences around the GOFLAGS, GOPROXY, and GOMOD.

    If I understand correctly what you are trying to do, then you need to enable the Go Modules support via Preferences | Go | Go Modules (vgo) and enable the Go Modules integration. Once you do this, you'll see that the GOFLAGS value will change.

    There you can also set the Proxy field value to configure the GOPROXY environment variable.

    The GOMOD difference comes from the directory where you invoked the go env command, as in this case they seem to be different directories. Invoke the command in the same directory in both IDE terminal and OS terminal and you'll see the same value. It indicates which, if any, go.mod file is used in the current command.

    Finally, I recommend upgrading to GoLand 2019.3 as it will automatically enable Go Modules support when it detects that the project is created in a directory with a go.mod file present.