Path Variables dialog has nothing to do with the environment variables.
Environment variables can be specified in your OS or customized in the Run configuration:

If you want to specify default environment variables for every new unit test configuration (as per this answer):
Run > Edit Configurations > Edit Configuration Templates > TestNG/JUnit > Environment Variables
Path Variables dialog has nothing to do with the environment variables.
Environment variables can be specified in your OS or customized in the Run configuration:

If you want to specify default environment variables for every new unit test configuration (as per this answer):
Run > Edit Configurations > Edit Configuration Templates > TestNG/JUnit > Environment Variables
I could not get environment variables to work when IntelliJ Build and run property was using Gradle. I am not sure what the root cause is, but switching to IntelliJ IDEA solved the problem. Go to Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle. Then change Build and run using: to IntelliJ IDEA.

IntelliJ IDEA global environment variable configuration - Stack Overflow
java - How do I add environment variables in IntelliJ Spring Boot project - Stack Overflow
java - IntelliJ - why does the terminal has different environment variables values - Stack Overflow
IntelliJ : executing a program with environment variables stored in a separated file - Stack Overflow
Videos
In my opinion the real issue is what Mat said.
If you want to launch IntelliJ from a shortcut, then you have to edit it a little bit:
Open the .desktop file, and add /bin/bash -c -i to the beginning of the launch command. The file should look something like this:
[Desktop Entry]
Exec=/bin/bash -i -c "/path/to/idea/bin/idea.sh" %f
Name=IntelliJ IDEA Ultimate
Type=Application
Version=1.0
The desktop file in ubuntu can be located at:
.local/share/applications/jetbrains-idea-ce.desktop
If the IDEA is installed via snap, then copying the desktop file is needed:
cp /var/lib/snapd/desktop/applications/intellij-idea-ultimate_intellij-idea-ultimate.desktop ~/.local/share/applications/
After editing the desktop file in ~/.local/share/applications/ the desktop menu should refresh itself in a few seconds.
I found a solution to set environment variables on IntelliJ that has been working very well for me, and is incredibly simple. Let me show you.
This is the program (you can copy and paste it) we're using to test:
package com.javasd.intelijenv;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.format("%s=%s%n", envName, env.get(envName));
}
System.out.println("My home directory: " + System.getenv("MY_VAR"));
}
}
This program basically loads all environment variables, show them on the console, and try to show an env variable. Also, it assumes that you had created the MY_VAR env variable before calling IntelliJ IDEA, by doing something like:
$ export MY_VAR="This is my adorable var :)"
$ idea
Please, notice that we're calling IntelliJ IDEA in the same terminal (or session, or window) where we created the environment variable. If you create the variable and call the IDEA from the icon, the solution won't work because the IDEA will create its own session.
So, if run it without the correct configuration you will get something line this in your console:

Please, notice that you have just a few variables, and that MY_VAR is null.
Here's configuration I use to load the environment variables:
- Click on the "Select Run/Debug Configurations" in your project and select "Edit Configurations":

- Then, click on the the button with "..." on the right side of the "Environment Variables" section:

- You'll see a pop-up. Check the checkbox on the bottom-left which has the label "Include parent environment variables":

That's it!!!
If you run your program now you will see something like this on your console:

You can see all the environment variables and, of course, your "MY_VAR" variable, with the right value!
Beyond the Basics
Usually, for security reasons, we don't want to keep all the environment variables visible. What we want to do is to make those variables visible only while the IntelliJ (or our program) is running.
So, no sensitive variables should be visible on the environment neither before you call Intellij nor after you close it.
Also, you want to keep those variables in a file (typically with a .env extension) to make it easy to manipulate and for security reasons.
To achieve this, there are some useful programs (you can Google them), but my favorite one is the env-cmd.
Let's say you have a test.env file with the following content:
MY_TEST_VAR=I live in the test.env file.
If you call IntelliJ by doing this:
$ env-cmd test.env idea
And edit your program to show "MY_TEST_VAR", and run it, you will see this on the IntelliJ's console:

But if you quit the IntelliJ, and look for your variable, you will see that the var doesn't exist (you can use env to confirm):

At this point, I hope you're able to play with your own solutions: create shell scripts with variables set inside, test other programs (direnv, autoenv, etc.), and so on.
If you are launching IntelliJ via the JetBrains ToolBox it will cache the $PATH variable so recent changes will not appear.
Just close and re-open JetBrains Toolbox.
I don't know about old IntelliJ versions, but in 2019.2.3 one can configure environment variables in project settings. Be aware, you need to restart existing terminal or create new terminal tab to see the effect.

As of March 14th 2017 it appears that someone has written a plugin which allows this.
Open settings, then select plugins In the search box search for “.env files support” and install it. After restarting IntelliJ you will have a new tab in the Run Configurations screen called EnvFile. The EnvFile tab will have a checkbox for enabling EnvFile support and a list where you can specify the env files you want to load prior to launching that specific run configuration; you need to set the env file option up for each run configuration.
I have a similar use case to yours and it works for me in specifying env files associated with a run configuration.
Additional Information on the plugin: https://plugins.jetbrains.com/plugin/7861-env-file
As of January 2026, IntelliJ IDEA supports this natively — no plugin required (see: link).
Most run configurations have an option to set environment variables:

The build settings window has a configuration tab with an option to change the environment variables.
http://www.jetbrains.com/idea/webhelp/run-debug-configuration-application.html
Otherwise you can use system system calls or the java language itself to change them during runtime.
How do I set environment variables from Java?

