IntelliJ not picking up environment variables when using ZSH?
Asked Answered
Y

5

8

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.

Yardmaster answered 27/4, 2020 at 22:52 Comment(0)
S
12

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

Selffulfillment answered 27/4, 2020 at 23:4 Comment(1)
~/.profile is the login shell script you would use for bash, the zsh equivalent login file is ~/.zprofile. That said, "Workaround 3" from that Jetbrains link seems more palatable to me because the /etc/zshrc (for Mac) explicitly suggests overrides in .zshrc: zsh $ cat /etc/zshrc | grep override # Setup user specific overrides for this in ~/.zshrc. See zshbuiltins(1) Chaing
C
7

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
Customable answered 5/4, 2022 at 21:39 Comment(1)
this is exactly my case. ThanksTurves
A
4

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
Applaud answered 2/8, 2021 at 8:53 Comment(1)
For now this is the only solution working for my setup (I use zsh)Seeley
T
1

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.

Towns answered 14/9, 2021 at 14:58 Comment(0)
K
0

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.

Krona answered 13/5, 2023 at 0:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.