Skip to content

bash not picking up /etc/environment #1405

Open

Description

Activity

  1. aseering commented on Nov 21, 2016

    @aseering
    Contributor

    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.

  2. stringhaml commented on Nov 23, 2016

    @stringhaml
    Author

    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

  3. jackchammons commented on Nov 23, 2016

    @jackchammons
    Contributor

    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.

  4. johnnyodonnell commented on Apr 5, 2017

    @johnnyodonnell

    How can you upgrade to a newer release?

  5. benhillis commented on Apr 5, 2017

    @benhillis
    Member

    Johnny (@johnnyodonnell) - supposedly you can download Creator's Update today via the media creation tool, but it "officially" releases on 4/11.

  6. rlabrecque commented on Apr 17, 2017

    @rlabrecque

    This is still a problem with 1703 unfortunately.

    Running bash --login doesn'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=1 to my /etc/environment file and RL_BASHRC=1 to ~/.bashrc
    testing.sh:

    #!/bin/bash
    echo RL_ENVIRONMENT: $RL_ENVIRONMENT
    echo RL_BASHRC: $RL_BASHRC
    

    WSL 16170 (1703/Creators Update):

    $ echo $RL_ENVIRONMENT
    
    $ echo $RL_BASHRC
    1
    $ sudo echo $RL_ENVIRONMENT
    
    $ sudo echo $RL_BASHRC
    1
    $ ./testing.sh
    RL_ENVIRONMENT:
    RL_BASHRC:
    $ sudo ./testing.sh
    RL_ENVIRONMENT: 1
    RL_BASHRC:
    

    Ubuntu 16.04:

    $ echo $RL_ENVIRONMENT
    1
    $ echo $RL_BASHRC
    1
    $ sudo echo $RL_ENVIRONMENT
    1
    $ sudo echo $RL_BASHRC
    1
    $ ./testing.sh
    RL_ENVIRONMENT: 1
    RL_BASHRC:
    $ sudo ./testing.sh
    RL_ENVIRONMENT: 1
    RL_BASHRC:
    

    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

    Somewhat related: #816

  7. thesmart commented on Dec 7, 2017

    @thesmart

    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?

  8. vient commented on Mar 1, 2018

    @vient

    Still not working on 1709 (16299.248).

  9. therealkenc commented on Mar 1, 2018

    @therealkenc

    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.

  10. wpwoodjr commented on Jan 2, 2019

    @wpwoodjr

    Is there any progress on getting WSL to pick up /etc/environment under Ubuntu? If not what is the best work around?

  11. falfiya commented on Feb 1, 2019

    @falfiya

    Still present in 1809. One workaround right now is to use /etc/profile or /etc/profile.d/. Those seem to actually be used, unlike /etc/environment.

  12. oldium commented on Sep 11, 2019

    @oldium

    I just tried it on build 18975 and WSL 2 (Ubuntu 18.04 LTS image) - /etc/environment is used by a call to bash -c "set | grep PATH".

  13. clearnote01 commented on Dec 23, 2019

    @clearnote01

    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

  14. 14 remaining items

  15. trallnag commented on Jul 31, 2022

    @trallnag

    Related: linux-pam/linux-pam#481


    Interesting finding: /etc/environment is parsed once sudo login is 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.d for that.


    I found a way to get into the WSL distribution from PowerShell that uses /bin/login and by that parses /etc/environment.

    wsl.exe -u root -- /bin/login -f <username>
    

    Found this by googling here: https://uzxmx.github.io/wsl-tricks.html

  16. lombervid commented on May 26, 2023

    @lombervid

    Any update on this? I still have this problem using Windows 11 build 22621.1702.

    I found a way to get into the WSL distribution from PowerShell that uses /bin/login and by that parses /etc/environment.

    wsl.exe -u root -- /bin/login -f <username>
    

    Found this by googling here: https://uzxmx.github.io/wsl-tricks.html

    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:

    $env:MYENV = "some-value"
    $env:WSLENV = "${env:WSLENV}::MYENV"

    And then setting my windows terminal profile:

    {
      "name": "Ubuntu",  
    - "source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc",
    + "commandline": "pwsh.exe --command \"wsl --cd ~\"",
    },

    Or executing directly from powershell:

    ubuntu

    This works, but I don't feel like this should be the way to do it.

  17. npuichigo commented on Jul 10, 2023

    @npuichigo

    any update?

  18. iamexe commented on Oct 2, 2023

    @iamexe

    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?

    7 years now...

  19. mikenunan commented on Nov 8, 2023

    @mikenunan

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

  20. anodynos commented on Nov 11, 2023

    @anodynos

    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 ;-)

  21. bryndin commented on Jun 13, 2024

    @bryndin

    7.5 years and ticking

    This bug breaks snap on Ubuntu:

    • Whatever packages snap installs get symlinked in /snap/bin
    • /snap/bin is supposed to get into PATH via /etc/environment, and that is broken on WSL by this bug.

    A simple fix is to add /snap/bin manually in .bashrc or .zshrc.

  22. dzciemix commented on Jul 5, 2024

    @dzciemix

    Workaround

    $ cat /etc/profile.d/path.sh
    export PATH="/opt/bin:$PATH"
    
  23. lucasfcnunes commented on Sep 3, 2024

    @lucasfcnunes

    dzciemix it worked!

  24. larsonmars commented on Nov 25, 2024

    @larsonmars

    Happy 8 years anniversary 🎂! Still breaks installations and scripts that assume /etc/environment is working, creating support overhead.

  25. borjamunozf commented on May 5, 2025

    @borjamunozf

    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.

    Workaround

    $ cat /etc/profile.d/path.sh
    export PATH="/opt/bin:$PATH"
    

    For some reason, this does not work neither.

  26. pa-0 commented on May 17, 2025

    @pa-0

    Workaround

    $ cat /etc/profile.d/path.sh
    export PATH="/opt/bin:$PATH"
    

    Even if this is a valid workaround, it's not an option if your default shell is zsh for example.

  27. doubleyewdee commented on Jun 23, 2025

    @doubleyewdee

    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

  28. mpleune-prattmiller commented on May 29, 2026

    @mpleune-prattmiller

    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?

  29. oldium commented on May 31, 2026

    @oldium

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions