-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use fresh environment block on new terminals in Windows #47816
Comments
Worse yet, if you have multiple instances of vscode running, all of them need to be killed and restarted for the environment variables to be updated for the sake of one window where you needed it. |
Actually it is stuck in a weird state. Two instances have different values for the same variable. One is updated while the other is not. Not sure how to reproduce it. I think it is somehow tied to different workspaces. It would be great if somebody could shine a light on how vscode powershell integrated terminal fetches the environment variable. |
Okay so I think I found two different issues.
|
@eslachance are you on Windows? Isn't the global node_modules bin directory added to PATH, I would have expected this to work? |
I believe what I added was a global module such as |
Git also seems to be affected by this. Specifically, the |
One thing that worked for me ( on mac ) was to add the environment variables to the bash profile. That way whenever you restart vscode or open a new terminal instance anything in the profile is loaded.
You can then either restart the terminal or use "source ~/.bash_profile" and the environment variable will be picked up. Hope that helps! :) |
What I ended up doing is installing PuTTY and running If only we could just converge on a single SSH suite inside of Windows, whether that's the WSL one, or the native port. I think that even PowerShell has some SSH functionality built-into sessions now. |
I have same issue on mac for .bash_profile changes to take effect, Either will have to restart whole vscode IDE or execute "source ~/.bash_profile". Apart from that I have issue with duplicated paths in PATH variable.
When I echo in mac terminal I get where as vscode integrated terminal outputs as Can you please resolve this. |
Thanks, @MirzaSikander! I couldn't figure out why the environment variable was hanging around. I was always re-opening the project via the Opening the folder by using the 'open folder' option did indeed load the new environment variable values! This is important when switching your AWS_PROFILE, which is needed for IAM authentication to create a token for kubernetes. |
Is there any plan as of right now to add this functionality? |
Same here, it's been bugging me for a while as I exclusively open via the taskbar. Nicely spotted, @MirzaSikander. This issue is more critical imo, as it's hard to even zero in on what's happening and it doesn't seem like it's by design, as opposed to having to close/reopen. |
I am a teacher on the Radboud University in the Netherlands and my students have a lot of problems with this issue. Most work on Windows 10 and for them the easiest work around is to restart their computers. Because this is counter intuitive, it often takes them a while to figure out how to solve it. So fixing this issue would be a great help to me and my students. |
This could probably be fixed by #70248 (comment) I'll take a note on that calling out this specific issue. |
Can the in my opinion super weird behavior of caching environment variables but only when working with recent projects be disabled somehow? I have exactly 0 understanding of the need for doing this, but hey, lets say it is useful for 'some scenarios'. Being able to not have this super annoying behavior would be quite beneficial! |
@woutervugt this isn't about caching and it's not a Vscode specific issue. The same thing happens if you have a command prompt or bash open, and change your environment variables - you have to close and reopen the prompt to see those changes. However, in the world of Vscode, all the terminals need to be restarted, which means all of the vscode instances, and that's why a solution has to be provided by the team to reload them without a full restart. So to be clear: the vscode team didn't cause this issue, it's inherent to all terminals, but we would welcome a solution from them with arms wide open. |
Thanks for your reply. I understand env vars are loaded at the Windows process level. Gonna test a bit and see what is happening! |
Ok, this is just crazy And it was not Ralph, nor Ralph1 (but Wouter, which it was somewhere before I did deployments for eh Ralph). So, now VSCode has a env var value that is not equal to what it was before I refreshed the process / window, and is also not equal to the actual value in Windows. Must be me but this is just really unexpected behavior. It seems that somewhere the env vars are persisted. Might be the POSH plugin, which truth be told has its fair share of weirdness) |
Made a screen recording file. If you want I can drop that somewhere. Must be a dev if you find it funny that I actually have a screen recording tool I didn't know and then see that it creates MHT files. Want me to send the MHT file :) I swear it won't cause harm!! lol |
Just reiterating here, as I think these last comments are added evidence, that the issue with opening via the taskbar should be prioritized over the need to close/reopen all terminal instances. Regardless of one's thoughts in regards to closing/reopening, at least it makes some sort of sense. Projects opened via the taskbar not picking up new values is just confusing. I probably wouldn't have figured that one out to this day if it wasn't for @MirzaSikander. |
Man you'd think someone would have figured this out, almost 5 years later... |
Yes, I commend Microsoft on solving 143k issues, and being the top editor for developers. You ousted Atom, and I absolutely adore VSCode. Still, after 5 years, this issue is position 175-ish most upvoted open issues and top 100-ish most open commented, so I don't feel it's unreasonable for it to get some attention and love? |
@eslachance the issue with this one is I think we'll need to write a new native node module that pulls the fresh environment block, and that's not really my area of expertise (C++, Rust or native Windows programming). Of course it's doable, but it would take a disproportionate amount of time to action relative to other issues. If we can do it reliably by shelling out to fetch the env block or via built-in node APIs this would be a lot easier to tackle. |
You can call PowerShell command from git-bash like this. export PATH=$PATH:$(powershell.exe invoke-command -scr "{[System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\") + \";\" + [System.Environment]::GetEnvironmentVariable(\"Path\", \"User\")}" | sed -e 's/\\/\//g' -e 's/C:/\/c/g' -e 's/;/:/g') |
There is now also a PowerShell package for refreshing environment variables: https://github.com/asheroto/Refresh-EnvironmentVariables Install-Script Refresh-EnvironmentVariables -Force
Refresh-EnvironmentVariables |
Are there any updates on this issue? It's been open for 6 years now. My issue is with This is the real issue: #101575 (comment) |
i used the solution mentioned in the comment right before yours, not sure if its applicable for you tho, seems like youre facing a different issue. i use this after installing a specific package in a script that im using
|
“Today, I encountered a situation where the VS Code terminal couldn’t read system environment variables because the vscode/bin path was set in my account environment. However, after changing it to the system environment path, everything worked fine.” 😊 |
2024.8.5 The problem remains |
Where do you set this? |
For me VSCODE can't read user variables, only system |
Was re-confirm this today on stable 1.96.0 on Windows 11, so the issue still exists. |
Yep, this is still routinely happening for me too. I suspect it might be an issue with windows explorer because the PATH for explorer.exe does not contain user PATH values. |
At the moment, if any environment variables change, or new "apps" are installed while VS Code is running, in order for those changes to be recognized VS Code needs to be closed and re-open.
For instance, when running
npm i -g <something>
orchoco install <package>
in another prompt or powershell window, those new commands are not recognized until the app is rebooted.It would be great if adding a new terminal instance with
+
would load these new variables/apps/notsurewhatterminologytouse.The text was updated successfully, but these errors were encountered: