The UI of Run/Debug Configurations has changed. Under 'Modify Options' select 'Environment Variables' under 'Operating System'.

Answer from Joe Tobin on Stack Overflow
🌐
JetBrains
jetbrains.com › help › idea › program-arguments-and-environment-variables.html
Program arguments, VM options, environment variables | IntelliJ IDEA Documentation
May 27, 2025 - For configuration through an .env file or a script – enter the path to the file or use the Browse for .env files and scripts button in the Environment variables field. In the case of multiple files, separate them with semicolons (;). This is the most common location of the option, which corresponds to run configurations such as Application, Maven, or Spring Boot.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 10751186096146-Environment-variables-in-Spring-Boot-run-configuration-aren-t-available-to-Gradle-during-build
Environment variables in Spring Boot run configuration aren't available to Gradle during build – IDEs Support (IntelliJ Platform) | JetBrains
March 28, 2023 - Your Gradle build will see the environment only if you run Gradle configuration from IntelliJ IDEA. ... Thanks for the response. If I'm understanding right, it sounds like an intentional design decision to not set the environment variables from a run configuration before the build happens? Also, you said that Spring Boot and Application configurations should not set the environment before the build, however Application DOES set the environment variable from the run configuration.
🌐
YouTube
youtube.com › watch
How To Set Environment Variables in Your Spring Boot Application | Read the variable | IntelliJ IDEA - YouTube
In this tutorial, you will learn how to set environment variable Spring Boot application, and also use the variable in the application.yml or application.pro...
Published   October 18, 2023
🌐
tutorialpedia
tutorialpedia.org › blog › how-do-i-add-environment-variables-in-intellij-spring-boot-project
How to Add Environment Variables in IntelliJ for Spring Boot Projects (application.properties Guide) — tutorialpedia.org
Spring Boot allows referencing environment variables in application.properties using the syntax ${VAR_NAME}. This lets you keep configuration centralized while pulling values from environment variables (set via IntelliJ, system, or deployment ...
🌐
CodingTechRoom
codingtechroom.com › question › how-to-add-environment-variables-in-your-intellij-spring-boot-project
How to Add Environment Variables in a Spring Boot Project Using IntelliJ IDEA - CodingTechRoom
// Example of defining an environment ... variables can help manage sensitive information such as API keys, database passwords, etc. Open your Spring Boot project in IntelliJ IDEA....
Find elsewhere
Top answer
1 of 11
26

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.

2 of 11
19

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:

  1. Click on the "Select Run/Debug Configurations" in your project and select "Edit Configurations":

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

  1. 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.

🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 20540208284434-Intellij-Spring-boot-isn-t-able-to-pass-environments-variables-when-I-made-run-Macbook-Apple-silicon
Intellij (Spring boot) isn't able to pass environments variables when I made run (Macbook Apple silicon). – IDEs Support (IntelliJ Platform) | JetBrains
* What went wrong: Execution failed for task ':edge-operator-mobile-service:bootRun'. > Process 'command '/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1. I tried to set the environment variable in application.properties the error was gone but a new error occurred.
🌐
CodingTechRoom
codingtechroom.com › question › -set-environment-variable-spring-boot-gradle-intellij
How to Set Environment Variables in Spring Boot Using Gradle and IntelliJ - CodingTechRoom
To set environment variables in Gradle, you can modify the build.gradle file and configure the 'bootRun' task to include the necessary environment variables. For IntelliJ IDEA, ensure that you configure the environment variables in the Run/Debug configurations, which is accessible from the top right corner of the IDE.
🌐
Medium
medium.com › @aqilzeka99 › how-to-work-productively-with-environment-variables-in-spring-boot-86af52b68dc8
How to Work Productively with Environment Variables in Spring Boot | by Agil | Medium
April 23, 2025 - To set environment variables: ... Now your variables are available in every terminal session. 6. You can see it in the terminal with bthe elow command: ... Let’s say you’re building a Spring Boot app. Instead of hardcoding credentials, configure your application.yml like this: spring: datasource: url: jdbc:postgresql://localhost:5432/mydb username: user password: ${DB_PASSWORD_DEV} If IntelliJ doesn’t automatically pick up your environment variables invalidate and restart your IntelliJ.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 10075122899986-How-to-use-env-or-envrc-files-to-pull-env-vars-for-run-debug-configurations
How to use .env or .envrc files to pull env vars for run/debug configurations? – IDEs Support (IntelliJ Platform) | JetBrains
February 13, 2023 - If you are working with Spring and IntelliJ. You should try without plugins to add this environment entry spring.config.import=optional:file:D:/IdeaProjects/[YOUR-PROJECT-HERE]/.env[.properties] .env[.properties] tells Spring Boot that .env should be treated as a properties file.
🌐
Stack Overflow
stackoverflow.com › questions › 47357761 › environment-variable-used-with-gradle-intellij-spring-boot
java - environment variable used with gradle intellij - spring boot - Stack Overflow
November 18, 2017 - setEnvVarRunConfiguration 'MyApplication', 'LOG_LEVEL', 'INFO' def setEnvVarRunConfiguration( final String configuration, final String envName, final String envValue ) { final javaExecRunConfiguration = { task -> task instanceof JavaExec && task.name == "run $configuration" } tasks.matching(javaExecRunConfiguration).all { environment envName, envValue } }
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 5818950617618-Is-there-any-good-way-to-use-env-file-in-bootrun
Is there any good way to use .env file in bootrun? – IDEs Support (IntelliJ Platform) | JetBrains
May 29, 2022 - We can run the spring boot project from the buttons at top-right corner. Is there any good way to use ".env" file in the project? We can configure environmental variables one-by-one in the Run/Debug configuration dialog, but it would be better if I could use ".env" file.
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-188768 › Environment-variables-set-in-run-configuration-not-set
Environment variables set in run configuration not set
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-341647 › Copy-a-Spring-Boot-properties-file-variable-as-an-environment-variable
Copy a Spring Boot properties file variable as an ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
JetBrains
jetbrains.com › help › idea › spring-boot.html
Spring Boot | IntelliJ IDEA Documentation
It includes all available properties from various configuration sources, such as application properties and environment variables. In Spring Boot version higher than 3.0, values provided by Spring Environment are fully sanitized (replaced with ...