4

EDIT in 2023: I have macOS 13.2 Ventura and vscode 1.74.3 installed now, and this problem isn't reproducing the same way anymore. It looks like this is due to a relatively new vscode feature, Terminal Environment inheritance which is running the login shell:

When VS Code is opened, it launches a login shell environment in order to source a shell environment. This is done because developer tools are often added to the $PATH in a shell launch script like ~/.bash_profile.

This doesn't change the question, about a general fix without every app needing to add this custom workaround.


I have the option "Reopen windows when logging back in" set, which on my 11.6 macbook will reopen apps like vscode and iTerm2 after I restart. I want the reopened windows to have the expected environment variables set.

Most apps will reopen with no problem, but in vscode I'll get the error The terminal process failed to launch: Path to shell executable "pwsh" does not exist. As far as I can tell, the problem is related to the system procedure for creating PATH not running for windows reopened at login. By launching bash I can see the process PATH environment variable is something like /usr/bin:/bin:/usr/sbin:/sbin which explains the "pwsh" does not exist error... (because pwsh is in /usr/local/bin/ which normally is in my PATH but is missing here.)

I could solve the immediate problem by specifying the full path to my shell executable in my vscode config, but other tools in /etc/paths wouldn't be included in PATH automatically either.

Is there some macOS setting I can change so that reopened windows have the right environment variables?

Or, I see that when iTerm2 reopens it starts my pwsh shell and somehow has the correct PATH -- could the vscode app copy the startup logic from iTerm2 to start with the right environment variables?

2
  • Does VSCode work if just started normally?
    – mmmmmm
    Commented Nov 27, 2021 at 12:45
  • @mmmmmm yes the vscode basic editor seems to work. The first big problem is activating the terminal only shows an error popup, and the terminal does not open. For extension that look for a program on the PATH (maybe python/golang) I assume they'll have problems working.
    – Carl Walsh
    Commented Nov 27, 2021 at 18:23

1 Answer 1

1

I don't think you can solve the root problem. Every app/command can set/reset its own Environment variables. The problem is really complicated, if there's a way to set a path globally so that it works in every case i would like to know it too. Thing is when you're launching a deamon - you have to set paths in plist file, because it gets a reset. When you run 'sudo su' - a reset and you have to edit /etc/sudoers. When you run a shell - a reset.

The app decides what environment variables it likes to have, so you usually mess up with specific app's config or the launch config. If the problem is with vscode and you can fix it by editing vscode's config - do it.

The most generic place where variables are stored is '/private/etc/paths', but something like /usr/local/bin should already be there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .