2

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 like pyenv shims and gcloud are also missing from the PATH so this doesn't solve the root problem.

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
    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
    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 .