'IntelliJ not picking up environment variables when using ZSH?

I am using oh-my-zsh for my terminal. I have set IntelliJ to use /bin/zsh as the shell path. However no environment variable in my .zshrc file ever seems to get picked up. I'm defining environment variables like this (for instance):

export GOOGLE_APPLICATION_CREDENTIALS="$HOME/mailcreds.json"

But if I run:

echo $GOOGLE_APPLICATION_CREDENTIALS

Nothing comes up.



Solution 1:[1]

Set environment variables in ~/.profile instead of ~/.bashrc or ~/.zshrc, see this issue for details.

Solution 2:[2]

For me, the issue was that I load tmux automatically using .zshrc.

I followed the solution here: https://youtrack.jetbrains.com/articles/IDEA-A-19/Shell-Environment-Loading

Wrapped just the export ZSH_TMUX_AUTOSTART=true like this:

if [ -z "$INTELLIJ_ENVIRONMENT_READER" ]; then
  export ZSH_TMUX_AUTOSTART=true
fi

Solution 3:[3]

For Ubuntu, I edited my IDE desktop launcher to run zsh with login interactive:

  1. Go to /usr/share/applications (where the desktop entry usually located).
  2. Edit jetbrains-idea.desktop(might be named differently).
  3. Change Exec field to include /bin/zsh -l -i -c "/opt/intellij/bin/idea.sh".

The final result of the file:

[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Ultimate Edition
Icon=/opt/intellij/bin/idea.svg
Exec=/bin/zsh -l -i -c "/opt/intellij/bin/idea.sh" %f
Comment=Capable and Ergonomic IDE for JVM
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea
StartupNotify=true

Solution 4:[4]

Shared the same wrong behavior with Intellij in Manjaro (Arch), which uses zsh by default.

The issue comes with Flatpak, switching to Snap or downloading binaries directly from vendor's page got this solved.

Is similar to this issue (PyCharm): https://github.com/flathub/com.jetbrains.IntelliJ-IDEA-Ultimate/issues/23.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CrazyCoder
Solution 2 Abdullah Javid
Solution 3
Solution 4 Felix Aballi