Cant set default environment variables in Goland Run/Debug configs

Does anyone know how to set default env variable like FUNCTIONAL=1 in goland IDE so that I can run functional tests from IDE.. I see an option called ‘defaults’ -> Go test -> Env variables.. but setting there doesnt seem to have any effect 

Official comment

Hi Prathap,


How do you create the tests after that? And what IDE version do you have?

Can you please that the Default Run Configuration looks like this (see below) when configured?


Thank you.


Hi @Florin.

I have the same problem. 

But the config env's are seted on one terminal.

$ export FOO=bar

and when i build with Run/Debug Configurations, the value is empty, but ...
when i run with

$ go run main.go

the variable is bar //correct

any ideas?

goland 2019.2


@Ricoterox your problem is a different one.

If you set the variable in a terminal inside the IDE, those won't be automatically sent to the run configurations.

You have to use the way mentioned above to set environment variables. Go to Run | Edit Configurations... | Templates | Go Build and set the environment variables there. Then all new run configurations will inherit those.

If you wish to set the variables for the terminal specifically, then go to Settings/Preferences | Tools | Terminal | Environment Variables. Note: the environment variables set here will only affect the GoLand terminal after it's closed and started again. And they will not affect the Run Configurations.

If you still have issues, please let me know.


Thank you Florin

i see what the problem was.

But i came up with another solution.

I create a makefile with a run target.


@echo "Running main.go"


this works perfectly with my problem.

But then I ended up using an .env file with all those keys.





Hi Danny. That doesn't look like a solution, but if it works for you, I guess that's ok. Please let us know if you need any further assistance.



Hello! I'm actually hitting the exact same bug. The environment variables are set in the configurations as you showed above, but they are not actually passed in when I run go build or test.

I am running

  • Goland 2019.2.3
  • Mac OS X 10.14.6
  • go1.13.3
  • I am building using go modules and the gvo integration + vendoring enabled

The following is the console output (sorry for the redacted parts):

GOROOT=/usr/local/Cellar/go/1.13.3/libexec #gosetup
GOPATH=/Users/antonio/go #gosetup
/usr/local/Cellar/go/1.13.3/libexec/bin/go build -i -o /private/var/folders/sj/31p3535x1kd8b1gd4774xm5x64c6rc/T/___go_build_git_yelpcorp_com_services_flink_operator_cmd_manager . #gosetup
/private/var/folders/sj/31p3535x1kd8b1gd4774xm5x64c6rc/T/___go_build_REDACTED #gosetup
F1021 19:10:16.326045 47223 main.go:64] Failed to get watch namespace: WATCH_NAMESPACE must be set
goroutine 1 [running]:

This is the environment setup


@Antonio, can you please confirm that there's no whitespace before `WATCH_NAMESPACE` in the environment variable?

You can also run the following line before your check for the variable to see if the variable is sent: "fmt.Println(os.Environ)".

Thank you.


You are right! *facepalm*


@... Hello, How can I append an environment variable into system environment variable in goland? Example, My system environment variable has this: `TName=a`, and I want add `b` to variable `TName`, I write `TNAME=%TNAME%;b`, but it doesn't work!

Thank you very much.


Double Pointer Hello, at the moment this is not possible in GoLand. Feel free to go to our YouTrack and create a new feature request.


I'm new to using Goland and loving it so far but this is the first issue I've run into and not been able to solve myself.

I am having the same issue where I've set the test config environment variables but the tests aren't picking them up for some reason. Upon debugging, I found that Goland was adding an extra `;` to the command it invoked. E.g. `key=value; command` instead of `key=value command` which worked locally whereas the former (which Goland created) did not.

I tweaked my test to just print the `os.Environ()` and so from my logs you can see what was invoked and what the environ read in the tests was (sorry for the verbosity):


SONOBUOY_CLI=/Users/jschnake/go/src/ KUBECONFIG=/Users/jschnake/.kube/config a=b; go test $GOTARGET/test/integration -update -v -tags integration -run 'TestPluginsPersistThroughLogQuery'


ENVIRON IS... [PATH=/usr/local/go/bin:/Users/jschnake/go/bin:/Users/jschnake/bin:/usr/local/bin:/Users/jschnake/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin TERM=xterm-256color COMMAND_MODE=unix2003 __INTELLIJ_COMMAND_HISTFILE__=/Users/jschnake/Library/Caches/JetBrains/GoLand2021.2/terminal/history/sonobuoy-history5 LOGNAME=jschnake XPC_SERVICE_NAME=0 __CFBundleIdentifier=com.jetbrains.goland SHELL=/bin/zsh GOPATH=/Users/jschnake/go USER=jschnake GOROOT=/usr/local/go TMPDIR=/var/folders/8j/c6w1d8tn3tsg3k9w7gc9mpk80000gp/T/ TERMINAL_EMULATOR=JetBrains-JediTerm LOGIN_SHELL=1 GO111MODULE=on SSH_AUTH_SOCK=/private/tmp/ XPC_FLAGS=0x0 TERM_SESSION_ID=f0399228-4525-47be-9779-0f9a322cba53 __CF_USER_TEXT_ENCODING=0x1F6:0x0:0x0 LC_CTYPE=en_US.UTF-8 HOME=/Users/jschnake SHLVL=1 PWD=/Users/jschnake/go/src/ OLDPWD=/Users/jschnake/go/src/ ZSH=/Users/jschnake/.oh-my-zsh PAGER=less LESS=-R LSCOLORS=Gxfxcxdxbxegedabagacad EDITOR=goland sono=/Users/jschnake/go/src/ _=/usr/local/go/bin/go]



None of those values I set were actually read in the code. For the record, I am running this as a Bash script instead of a `go test` since it lined up with other parts of my dev flow already.

Is this a bug or is there something I could have done to change how that was run?

GoLand 2021.2.2
Build #GO-212.5080.74, built on August 31, 2021
Licensed to GoLand Evaluator
Expiration date: October 15, 2021
Runtime version: 11.0.11+9-b1504.16 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.5
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Registry:, ide.completion.variant.limit=500
Non-Bundled Plugins: com.planetexpress.go_struct_tag_generator (1.2.8)


Schnake John, I can't reproduce the issue with extra ; so far in my environment. So, I'd like to ask you some details:

  • Where did you specify your environment variables initially (.zshrc, .bash_login, etc.)?
  • Have you specified them in Run | Edit Configurations as well? Could you please attach a screenshot?
  • Are you using .env files in your project? If so, you can try out the EnvFile plugin.

It would be great if you could provide the exact steps to reproduce to understand your case better.

Thank you.


Please sign in to leave a comment.