You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exit bash, re-open, and do a printenv they are not listed.
Reacted by Johnny, Pavel Martynov, Dominik Ruf, Kyle Anderson, Jean-Louis Rigau, falfia falfiya, Peter Bowman, Christoph Pitschmann, Alexey Krystal, Frederik Aalund and 31 more
Thanks Lance Stringham (@stringhaml) for posting! I believe this is conceptually the same issue as #816 ; it probably shares the same workaround.
WSL team, any further thoughts on that issue? I feel like I recall a bunch of discussion about it somewhere on one of these tickets prior to the Anniversary release, but I haven't heard much since.
Thanks for your response Adam Seering (@aseering)! I tried adding the --login option as described in #816 but it didn't resolve the issue. I should also mention I'm running on the following version of windows:
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.14393 N/A Build 14393
Lance Stringham (@stringhaml) Upgrading to a newer release of Windows via the insider program and using the workaround from #816 should fix this issue. Let us know if that works for you.
Using sudo su - does pick up /etc/environment and functions the same in both WSL and Ubuntu
Using sudo su -; su defaultuser does cause WSL to work as expected in this scenario.
I also use HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss AppendNtPath 0, since I was hoping that would help. I could see this happening to not have /etc/environment stomp on
It's been over a year and there still isn't a way to properly load the environment in Ubuntu? This is basic stuff. Are there any updates on how to source /etc/environment as it would in any standard Ubuntu install?
Reacted by Dominik Ruf, Gabriel Zapata, Bomin Zhang, Ron Wolf and Angelos Pikoulas
This got marked as a dupe of #816 a long time ago, but that issue was hence marked fixinsiderbuilds. I think it was marked as such because quoth:
As of build 16188 when running bash.exe without arguments (or with the ~ argument) bash will be launched as a login shell.
/etc/environment would be a different kettle of fish. This issue was conveniently never closed so I'll just de-dupe. Ref #352 which is along the same PAM lines.
Reacted by Riley Labrecque, vient, lju and Matthew Sundberg
After sudo login I am able to use variables set in /etc/environment. Interestingly WSL with Ubuntu doesn't seem to read variables set in ~/.pam_environment
Reacted by Sebastian König, Chaoses-Ib, Angelos Pikoulas and Alexander Novotny
Jack Hammons (@jackchammons)therealkenc It's been 6 years since this was opened, 4+ years since de-duped from #816 . 3 years since linked to #4232, and since then no maintainers from MS have commented or provided update on these two critical bugs. Are these things on any internal roadmap or associated with any project plan to be done in the next year? Or better yet, could you comment as to whether or not anyone is actively working on them?
I have just found my way here after spending an incredible amount of time trying to do what seems to be the most simple thing: set an env var globally inside of a distro or across all distros. ChatGPT thought it was possible to assign them in an [environment] section in /etc/wsl.conf or the system-level .wslconfig, which would indeed do the job nicely, but appears the bot was hallucinating that one.
Although this present issue is about bash specifically, for many use cases it would be helpful to have this not be shell-dependent. In my own case as a PowerShell-first user, the bash profile workarounds are not that helpful, and what should we do, define these things differently for every different shell type? In a corporate environment like mine we want to have a pre-configured distro with things like SSL config vars set up correctly, so that things work right out of the box without every dev having to configure their profiles.
The WSLENV workaround is about the only one that makes sense in that context, but is ugly as it means pushing profile changes to Windows desktops rather than just tailoring our WSL distro. The config sections suggested by ChatGPT would be dead simple to implement surely, and gets around any messing about with PAM etc. Can we have something like that, please please please???
To celebrate 🎂 the 7 years anniversary of this issue in 10 days, I present you my workaround, based on Sebastian König (@smaktacular) 's one, that combines /etc/environment & your current $PATH set elsewhere (eg Windows Paths set by WSL, other export PATH in .bashrc/.zshrc etc):
At the end of your .bashrc or .zshrc add the following:
export PATH_TEMP=$PATH
while read line; do export $line; done < /etc/environment
# $PATH now is "/some/paths:/..." but we need to omit first & last chars (the quotes)
export PATH=$PATH_TEMP:${PATH:1:${#PATH}-2}
unset PATH_TEMP
Done - It took me a bit more than 7 minutes, it will take you a bit more than 7 seconds.
Happy 7 years anniversary! 🥳 🎆 🎈
PS:> Make sure you have a newline at the end of /etc/environment otherwise read line breaks ;-)
Reacted by Simo Kivistö, davidklg, 3dfactor, Baptiste Desbiolles, Jonathan Hu, theGuiltyMan, Giacomo Russo, Levi Schwarzman and redfave
Reacted by Jan Bielak, vient, Matt Zinkevicius, Abdul Derh, Bill Wood, 3dfactor, Jeffrey Liu and Levi Schwarzman
Happy 8 years anniversary 🎂! Still breaks installations and scripts that assume /etc/environment is working, creating support overhead.
Reacted by vient, freedxmgxd, Lucas Fernando Cardoso Nunes, Angelos Pikoulas, Ridwan Faiz, Jonathan Stucklen, Giacomo Russo, Alejandro Pérez, Levi Schwarzman, BMF and 4 more
Any update here? Facing this issue in a OOBE script for custom distribution build that assumes /etc/environment or /etc/profile.d for running certain command avalable in updated PATH.
Just stumbled on this. I'm using WSL2 via work devboxes temporarily (MacBook is in the shop) and needed to use draw.io, which has a Snap package I chose to avail myself of. I guess /etc/environment just isn't loaded, but I am wondering why that would be the case at this point? As I understand it, the default experience (Ubuntu 24.04) is using systemd, I have a real init root, and so on. Genuinely surprised, and a bit dismayed at lack of response on this issue since it's so foundational and just "weird" friction as an end-user, especially as a nine year old issue apparently.
Yes, I can work around this, or I could (maybe should) just use Homebrew here, but I was hoping to find some deep technical lore about why this behavior is what it is, especially now, with the stack being a thin/light VM where I'd expect things to work as if I was in a real Ubuntu VM vs. having this kind of magic. Especially since the Windows devbox in question was stood up in late 2024, so it's very up-to-date and not beholden to legacy detritus.
Light snooping shows me that WSL "logins" are not real logins as far as PAM is concerned, but I'm sort of shocked there's no .wslconfig machinery that allows for this. Hoping the WSL team can shed light on this peculiarity.
WSL should, ideally, "just be Linux" as much as it can be, and in many ways it is, but these papercuts are tough for people with external experience coming in and trying to get up and running, or following guides that do not factor in WSL idiosyncracies. Which they, the guide authors, should really never need to do. /soapbox
Reacted by Angelos Pikoulas, Lucas Fernando Cardoso Nunes, login0false, Joe Profeta, jankapte, davisnw, Mitchell Pleune, Carter and redfave
This is crazy. The wsl.exe -u root -- /bin/login -f <username> hack does cause /etc/environment to load, but breaks DISPLAY with WSLg, and also does not work unless you change everything that launches wsl... terminal, vscode, etc. Why are we not just always launching login shells? I don't think there would be... any?... downsides?
This is crazy. The wsl.exe -u root -- /bin/login -f <username> hack does cause /etc/environment to load, but breaks DISPLAY with WSLg, and also does not work unless you change everything that launches wsl... terminal, vscode, etc. Why are we not just always launching login shells? I don't think there would be... any?... downsides?
What is crazy? WSL correctly injects DISPLAY environmental variable, so user root (-u root argument) has it. It is not WSL's fault that the hack does not forward it to user login shell.
Activity
aseering commentedon Nov 21, 2016
Thanks Lance Stringham (@stringhaml) for posting! I believe this is conceptually the same issue as #816 ; it probably shares the same workaround.
WSL team, any further thoughts on that issue? I feel like I recall a bunch of discussion about it somewhere on one of these tickets prior to the Anniversary release, but I haven't heard much since.
stringhaml commentedon Nov 23, 2016
Thanks for your response Adam Seering (@aseering)! I tried adding the --login option as described in #816 but it didn't resolve the issue. I should also mention I'm running on the following version of windows:
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.14393 N/A Build 14393
jackchammons commentedon Nov 23, 2016
Lance Stringham (@stringhaml) Upgrading to a newer release of Windows via the insider program and using the workaround from #816 should fix this issue. Let us know if that works for you.
johnnyodonnell commentedon Apr 5, 2017
How can you upgrade to a newer release?
benhillis commentedon Apr 5, 2017
Johnny (@johnnyodonnell) - supposedly you can download Creator's Update today via the media creation tool, but it "officially" releases on 4/11.
rlabrecque commentedon Apr 17, 2017
This is still a problem with 1703 unfortunately.
Running
bash --logindoesn't help.Right now there seems to be no way to set an environment variable that is used in all contexts?
I tested this with WSL and Ubuntu Server 16.04. I was expecting WSL to behave just like Ubuntu in this case.
I added
RL_ENVIRONMENT=1to my/etc/environmentfile andRL_BASHRC=1to ~/.bashrctesting.sh:
WSL 16170 (1703/Creators Update):
Ubuntu 16.04:
Using
sudo su -does pick up/etc/environmentand functions the same in both WSL and UbuntuUsing
sudo su -; su defaultuserdoes cause WSL to work as expected in this scenario.I also use HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss AppendNtPath 0, since I was hoping that would help. I could see this happening to not have
/etc/environmentstomp onSomewhat related: #816
thesmart commentedon Dec 7, 2017
It's been over a year and there still isn't a way to properly load the environment in Ubuntu? This is basic stuff. Are there any updates on how to source /etc/environment as it would in any standard Ubuntu install?
vient commentedon Mar 1, 2018
Still not working on 1709 (16299.248).
therealkenc commentedon Mar 1, 2018
This got marked as a dupe of #816 a long time ago, but that issue was hence marked fixinsiderbuilds. I think it was marked as such because quoth:
/etc/environmentwould be a different kettle of fish. This issue was conveniently never closed so I'll just de-dupe. Ref #352 which is along the same PAM lines.wpwoodjr commentedon Jan 2, 2019
Is there any progress on getting WSL to pick up /etc/environment under Ubuntu? If not what is the best work around?
falfiya commentedon Feb 1, 2019
Still present in 1809. One workaround right now is to use
/etc/profileor/etc/profile.d/. Those seem to actually be used, unlike/etc/environment.oldium commentedon Sep 11, 2019
I just tried it on build 18975 and WSL 2 (Ubuntu 18.04 LTS image) -
/etc/environmentis used by a call tobash -c "set | grep PATH".clearnote01 commentedon Dec 23, 2019
After
sudo loginI am able to use variables set in /etc/environment. Interestingly WSL with Ubuntu doesn't seem to read variables set in ~/.pam_environment14 remaining items
trallnag commentedon Jul 31, 2022
Related: linux-pam/linux-pam#481
Interesting finding:
/etc/environmentis parsed oncesudo loginis performed. Why does the default login not work?Does anybody know what tool WSL uses to perform the login? Maybe what is missing is a dedicated config in
pam.dfor that.I found a way to get into the WSL distribution from PowerShell that uses
/bin/loginand by that parses/etc/environment.Found this by googling here: https://uzxmx.github.io/wsl-tricks.html
lombervid commentedon May 26, 2023
Any update on this? I still have this problem using Windows 11 build 22621.1702.
This works for me, but then every time I open VS Code within WSL, it opens from Windows' file system instead of WSL's
I ended up using WSLENV to set my environment variables. I added something like this to my Powershell
$PROFILE:And then setting my windows terminal profile:
{ "name": "Ubuntu", - "source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc", + "commandline": "pwsh.exe --command \"wsl --cd ~\"", },Or executing directly from powershell:
This works, but I don't feel like this should be the way to do it.
npuichigo commentedon Jul 10, 2023
any update?
iamexe commentedon Oct 2, 2023
7 years now...
mikenunan commentedon Nov 8, 2023
I have just found my way here after spending an incredible amount of time trying to do what seems to be the most simple thing: set an env var globally inside of a distro or across all distros. ChatGPT thought it was possible to assign them in an
[environment]section in/etc/wsl.confor the system-level.wslconfig, which would indeed do the job nicely, but appears the bot was hallucinating that one.Although this present issue is about bash specifically, for many use cases it would be helpful to have this not be shell-dependent. In my own case as a PowerShell-first user, the bash profile workarounds are not that helpful, and what should we do, define these things differently for every different shell type? In a corporate environment like mine we want to have a pre-configured distro with things like SSL config vars set up correctly, so that things work right out of the box without every dev having to configure their profiles.
The WSLENV workaround is about the only one that makes sense in that context, but is ugly as it means pushing profile changes to Windows desktops rather than just tailoring our WSL distro. The config sections suggested by ChatGPT would be dead simple to implement surely, and gets around any messing about with PAM etc. Can we have something like that, please please please???
anodynos commentedon Nov 11, 2023
To celebrate 🎂 the 7 years anniversary of this issue in 10 days, I present you my workaround, based on Sebastian König (@smaktacular) 's one, that combines
/etc/environment& your current $PATH set elsewhere (eg Windows Paths set by WSL, other export PATH in.bashrc/.zshrcetc):At the end of your
.bashrcor.zshrcadd the following:Done - It took me a bit more than 7 minutes, it will take you a bit more than 7 seconds.
Happy 7 years anniversary! 🥳 🎆 🎈
PS:> Make sure you have a newline at the end of
/etc/environmentotherwise read line breaks ;-)bryndin commentedon Jun 13, 2024
7.5 years and ticking
This bug breaks
snapon Ubuntu:snapinstalls get symlinked in/snap/bin/snap/binis supposed to get intoPATHvia/etc/environment, and that is broken on WSL by this bug.A simple fix is to add
/snap/binmanually in.bashrcor.zshrc.dzciemix commentedon Jul 5, 2024
Workaround
lucasfcnunes commentedon Sep 3, 2024
dzciemix it worked!
larsonmars commentedon Nov 25, 2024
Happy 8 years anniversary 🎂! Still breaks installations and scripts that assume /etc/environment is working, creating support overhead.
borjamunozf commentedon May 5, 2025
Any update here? Facing this issue in a OOBE script for custom distribution build that assumes /etc/environment or /etc/profile.d for running certain command avalable in updated PATH.
For some reason, this does not work neither.
pa-0 commentedon May 17, 2025
Even if this is a valid workaround, it's not an option if your default shell is zsh for example.
doubleyewdee commentedon Jun 23, 2025
Just stumbled on this. I'm using WSL2 via work devboxes temporarily (MacBook is in the shop) and needed to use draw.io, which has a Snap package I chose to avail myself of. I guess /etc/environment just isn't loaded, but I am wondering why that would be the case at this point? As I understand it, the default experience (Ubuntu 24.04) is using systemd, I have a real
initroot, and so on. Genuinely surprised, and a bit dismayed at lack of response on this issue since it's so foundational and just "weird" friction as an end-user, especially as a nine year old issue apparently.Yes, I can work around this, or I could (maybe should) just use Homebrew here, but I was hoping to find some deep technical lore about why this behavior is what it is, especially now, with the stack being a thin/light VM where I'd expect things to work as if I was in a real Ubuntu VM vs. having this kind of magic. Especially since the Windows devbox in question was stood up in late 2024, so it's very up-to-date and not beholden to legacy detritus.
Light snooping shows me that WSL "logins" are not real logins as far as PAM is concerned, but I'm sort of shocked there's no
.wslconfigmachinery that allows for this. Hoping the WSL team can shed light on this peculiarity.WSL should, ideally, "just be Linux" as much as it can be, and in many ways it is, but these papercuts are tough for people with external experience coming in and trying to get up and running, or following guides that do not factor in WSL idiosyncracies. Which they, the guide authors, should really never need to do. /soapbox
mpleune-prattmiller commentedon May 29, 2026
This is crazy. The
wsl.exe -u root -- /bin/login -f <username>hack does cause/etc/environmentto load, but breaksDISPLAYwith WSLg, and also does not work unless you change everything that launches wsl... terminal, vscode, etc. Why are we not just always launching login shells? I don't think there would be... any?... downsides?oldium commentedon May 31, 2026
What is crazy? WSL correctly injects
DISPLAYenvironmental variable, so userroot(-u rootargument) has it. It is not WSL's fault that the hack does not forward it to user login shell.