Shell Environment Loading

On macOS, an app launched by a GUI launcher (Finder, Dock, Spotlight, etc.) inherits a relatively empty environment, and there are no sane ways to change it. The situation caused complaints about tools working in a terminal not working when launched from the IDE. That is why the IDE attempts to load a shell environment on startup. To do this, it starts a shell in background and instructs it to run a helper process. And since 2021.2, the IDE shows a notification when the loading fails.

The most common reason is a shell initialization script interacting with a terminal. The IDE has to use the -i option to run a shell in the interactive mode because environment modifications usually occur in ~/*rc scripts, and these scripts take the ability to interact with a terminal for granted. Unfortunately, a shell launched from the IDE has no access to a terminal, and the loading either fails with an error or times out (for more details, look for the "can't get shell environment" line in the log).

To fix the loading and get rid of the notification, please change the script so that all possible terminal interactions are skipped when a shell is launched by the IDE; one possible way is to put them inside conditional blocks:

if [ -z "$INTELLIJ_ENVIRONMENT_READER" ]; then
...
fi
23 out of 74 found this helpful
3 comments

I got this error message on startup:

IntelliJ IDEA has failed to load the environment from '/usr/local/bin/zsh'. Integration with tools that rely on environment variables may work incorrectly.

The error popup directed here, but nothing on this page addresses what to do if we don't have zsh located in /usr/local/bin.

Is there a setting to change the location IntelliJ uses for zsh?

0

@Matthew That message means either there is no '/usr/local/bin/zsh' in your system or the IDE is slow to use the zsh shell to get the environment variables so it gave up and shows that notification.

The IDE uses the `SHELL` environment variables to find your system default shell and runs it to get all environment variables.
Please check if you have '/usr/local/bin/zsh' in your system. If you don't have zsh in that folder, it means you have configured your default shell in the system to the wrong path.
macOS by default has '/bin/zsh` in a system instead of that path.

If you have '/usr/local/bin/zsh`, check running zsh -l is faster or if it needs several seconds. Also, try suggestions here to see if it fixes your issue: https://youtrack.jetbrains.com/issue/IDEA-276617/PhpStorm-has-failed-to-load-the-environment-from-bin-zsh.-Integration-with-tools-that-rely-on-environment-variables-may-work#focus=Comments-27-5290436.0-0

Edited by Lejia Chen
0

Hmmm, between using chsh to make sure my default zsh was /bin/zsh and rebooting, the issue seems to have gone away.

0

Please sign in to leave a comment.

Have more questions?

Submit a request