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.

Answer from Dávid Leblay on Stack Overflow
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.

🌐
Emmanuel Bernard
emmanuelbernard.com › blog › 2012 › 05 › 09 › setting-global-variables-intellij
Setting global environment variables in IntelliJ IDEA and other test config goodies - Emmanuel Bernard
May 8, 2012 - Alternatively, you can set an environment variable globally in IntelliJ - what they call parent environment variables. Go to Preferences and search for Path Variables. Set your global environment variables here and you are good to go.
Discussions

intellij Terminal environment variable set global - Stack Overflow
I'm trying to set a environment variable for the intellij terminal gobally for all projects. Up to now I only found the setting in File>Settings>Tools>Terminal but somehow this is not applied throu... More on stackoverflow.com
🌐 stackoverflow.com
IntelliJ HTTP Client Is it possible to define constant global variables or shared environment variables - Stack Overflow
I'm trying IntelliJ HTTP Client and I know that I can set environment variables and dynamic global variables in pre-request or post-request section. However is it possible to define some constant g... More on stackoverflow.com
🌐 stackoverflow.com
Setting up and using environment variables in IntelliJ Idea - Stack Overflow
I set up an environment variable (Under IDE Settings -> Path Variables) APP_HOME = /path/to/app_home One of my tests is failing however with System.out.println("APP HOME: " + APP... More on stackoverflow.com
🌐 stackoverflow.com
Setting Environment Variables using Gradle with IntelliJ IDEA
Using Gradle Properties: This isn't ideal in my case, because the API keys need to be refreshed frequently No matter where you put them when the keys refresh you have to change them. So why is having to change them in your env variables any different than having to change them in gradle.properties? FWIW, I put the keys for our nexus repo in gradle.properties (my local one, not the one in the repo that gets committed) More on reddit.com
🌐 r/IntelliJIDEA
2
4
July 25, 2023
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360008117040-Global-Environment-Variables
Global Environment Variables – IDEs Support (IntelliJ Platform) | JetBrains
April 15, 2020 - In general is there a way to use access enviornment variables when paths need to be configured, something like $PROJECT_DIR$ ? For example: In Settings > "Languages & Frameworks" > Dart I'm asked to enter the "Dart SDK path", what I'd like to do is set a "Global environment variabe", for instance in a shell script "export DART_SDK=/opt/dartsdk", and then in "Dart SDK path" enter: $DART_SDK$, or some such.
🌐
codestudy
codestudy.net › blog › intellij-idea-global-environment-variable-configuration
How to Set Global Environment Variables in IntelliJ IDEA for All Run Configurations (Linux Guide) — codestudy.net
Environment variables are key-value pairs that configure system behavior and application settings. In IntelliJ IDEA, run configurations often require variables like API keys, database URLs, or paths to resources.
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-141832 › Explicit-global-environment-variables-configuration
Explicit global environment variables configuration
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Iditect
iditect.com › program-example › intellij-idea-global-environment-variable-configuration.html
IntelliJ IDEA global environment variable configuration
... On the Welcome screen, click on "Configure" at the bottom right. ... In the "Custom Properties" dialog, you can add environment variables in the format name=value. For example, to set a global environment variable named MY_VARIABLE with the value my_value, add the following line:
Find elsewhere
🌐
Medium
medium.com › @guytheuws › mac-use-environment-variables-in-intellij-6b5772623677
Mac: use environment variables in IntelliJ | by Guy Theuws | Medium
January 18, 2020 - Figure 1. IntelliJ run configuration screen. 1) Run Configuration dropdown 2) Option to export configuration 3) Set environment variables through VM options 4) Set environment variables through environment variables
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 205820189-How-to-set-default-environment-variables-
How to set "default" environment variables? – IDEs Support (IntelliJ Platform) | JetBrains
May 3, 2017 - Please, go to `Run| Edit Configurations| Defaults| Python tests| Unitests/Nosetests/...` and specify your environment variables in "Environment variables" field, then apply changes.
🌐
JetBrains
jetbrains.com › help › idea › program-arguments-and-environment-variables.html
Program arguments, VM options, environment variables | IntelliJ IDEA Documentation
May 27, 2025 - For quick configuration – type the environment variables directly into the Environment variables field, using the following format: VAR1=ABC;VAR2=CDE.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360010430799-Global-Environment
Global Environment – IDEs Support (IntelliJ Platform) | JetBrains
February 15, 2021 - This type of feature is needed so that when I commit .idea/libraries/Dart_SDK.xml into a git repo and someone else checks it out will very likely have the dart-sdk installed at a different location so this needs to be a "variable" not hard-coded to a specific path. ... In Windows 8, the fastest navigation to change environment and user system variables is to use search.
🌐
JetBrains
youtrack.jetbrains.com › projects › IDEA › issues › IDEA-141832 › Explicit-global-environment-variables-configuration
Explicit global environment variables configuration - YouTrack
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions.
🌐
JetBrains
jetbrains.com › help › idea › http-client-variables.html
HTTP Client variables | IntelliJ IDEA Documentation
Access using client.variables.environment or request.environment. Global variables defined in response handler and pre-request scripts.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360010612199-Unable-to-set-environmental-variables-for-Gradle-build
Unable to set environmental variables for Gradle build – IDEs Support (IntelliJ Platform) | JetBrains
April 19, 2021 - For that syntax I use either user specific environment variables - or global environment variables. I personally don't like the gradle.properties for any sensitive information as I quickly focus on code and check sensitive information into the source repository... which is an oops by my account. Furthermore, using IntelliJ Run/Debug Configuration for these parameters are good per project, and/or when you run from within IntelliJ - which is not ideal if you find yourself reusing the same credentials over and over.
🌐
Medium
medium.com › @AlexanderObregon › working-with-environment-variables-in-intellij-idea-a-guide-12876bb796c5
Working with Environment Variables in IntelliJ IDEA — A Guide
April 28, 2024 - Learn how to effectively manage environment variables in IntelliJ IDEA, simplifying application configuration and enhancing development workflow.