Nespony
Nespony

Reputation: 1371

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.

Upvotes: 9

Views: 19715

Answers (5)

Chinna
Chinna

Reputation: 101

I solved it by opening Intellij using the terminal. You need to create Command Line Launcher if one doesn't exist.

  1. Go to Tools -> Create Command-line Launcher
  2. Then choose the location you prefer
  3. Go to your terminal, and use that launcher command: idea

This will open Intellij and start your app, this should be able to access your system environment properties.

Upvotes: 0

u-ways
u-ways

Reputation: 7754

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 or /var/lib/snapd/desktop/applications if you're using Snap).
  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

Upvotes: 4

Abdullah Javid
Abdullah Javid

Reputation: 81

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

Upvotes: 7

Felix Aballi
Felix Aballi

Reputation: 949

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.

Upvotes: 1

CrazyCoder
CrazyCoder

Reputation: 402325

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

Upvotes: 12

Related Questions