Skip to content
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

[Question] How to remove Windows pathes from WSL PATH? #1493

Closed
yhvicey opened this issue Dec 12, 2016 · 49 comments
Closed

[Question] How to remove Windows pathes from WSL PATH? #1493

yhvicey opened this issue Dec 12, 2016 · 49 comments
Assignees

Comments

@yhvicey
Copy link

yhvicey commented Dec 12, 2016

Is there any way to remove Windows pathes from my WSL PATH? Like some statement in some startup script or something.

@ddfznt

This comment has been minimized.

@fpqc
Copy link

fpqc commented Dec 12, 2016

There is also a registry key that just disables it entirely.

@benhillis
Copy link
Member

benhillis commented Dec 12, 2016

When I wrote this feature I added a registry key to opt out of the behavior in case it caused people issues:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss]
"AppendNtPath"=dword:00000000

@carlpaten
Copy link

That's a super interesting feature, I'm surprised at how little it's been advertised.

@NgxDev
Copy link

NgxDev commented Nov 22, 2017

@benhillis I've just tried that registry key. It doesn't seem to be working anymore 😞. Closed/reopened Bash on Ubuntu on Windows after adding the key and echo $PATH still spits out the same as before, a lot of /mnt/c/Program Files/...
Any change on that?
I've finally decided to give up WSL after struggling with it for so long, and installed Node on Windows to be able to work. Because it is impossible to work on some projects (depending on what packages/dependencies they have, I guess).

EDIT: I've also found the other solution and decided to try that as well, since I actually had WSL installed from the Windows Store:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LxssManager]
"DistributionFlags"=dword:fffffffd

At first I thought it worked, but it turns out I still had the following line (which I had found in the mean time) in my .bashrc:

PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')

After commenting it, it looks like none of the 2 Registry fixes actually work anymore.
Back to using WSL 😁 though, hopefully the script added in my .bashrc has solved all my npm issues and not cause any new issues. I'll find out soon enough.

@MikeGitb
Copy link

Can we please have a fix for this issue (preferably one, that doesn't invole making changes to the registry)? I understand that interop might be useful for some people, but for me it just clutters up the PATH variable (and consequently auto complete in bash and leads to occasional issues when linux tools get confused.

The way I see it, running windows binaries from inside Linux is the exception and not the rule, so I don't understand, why those paths get appended by default.

As a general comment: It would be nice to have a more extensive configuration tool in which I can set such things on a per distribution basis and which preferably has a gui to it.

@fpqc
Copy link

fpqc commented Apr 25, 2018

There is a solution now in wsl.conf.

@Brian-Perkins
Copy link

See WSLENV usage.

@TickleThePanda
Copy link

I've tried to look at the WSLENV usage or at wsl.conf but I'm struggling to understand what I need to do to remove these paths. Can somebody point me in the right direction, please?

@benhillis
Copy link
Member

Manually setting your path in your bashrc is probably your best bet. I am working on a change now to add this option to wsl.conf.

@TickleThePanda
Copy link

I went with @ddfznt's override as it works well for me but it would be nice to see something elegant! 😄

@yshterev
Copy link

yshterev commented Jun 8, 2018

If you use root = /

PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/(c|d)\// } split(/:/));')

@ysc3839
Copy link

ysc3839 commented Jun 11, 2018

WSL_DISTRIBUTION_FLAGS

typedef enum _WSL_DISTRIBUTION_FLAGS { 
  WSL_DISTRIBUTION_FLAGS_NONE                   = 0,
  WSL_DISTRIBUTION_FLAGS_ENABLE_INTEROP         = 1,
  WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH         = 2,
  WSL_DISTRIBUTION_FLAGS_ENABLE_DRIVE_MOUNTING  = 4
} WSL_DISTRIBUTION_FLAGS;

This flag is stored in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{GUID}\Flags. It's default value is 7.

@Biswa96
Copy link

Biswa96 commented Jun 11, 2018

There is another DWORD registry InteropEnable. Does that work on Store WSL apps? @benhillis

@benhillis
Copy link
Member

We are not documenting the registry keys themselves, just the flags to the configure API. The keys are subject to change.

@ysc3839
Copy link

ysc3839 commented Jun 11, 2018

@benhillis Should add a command to change this flag in wslconfig.

@benhillis
Copy link
Member

As I said above, I will be adding this flag to wsl.conf.

@benhillis benhillis self-assigned this Jun 13, 2018
@Brian-Perkins
Copy link

Insider Build 17713 contains wsl.conf additions to control this.

@Biswa96
Copy link

Biswa96 commented Jul 11, 2018

@Brian-Perkins Just a question, isn't WSL getting too dependent on WSL.conf file. Isn't it takes some time to open that file and parsing all the options?

@benhillis
Copy link
Member

The amount of time parsing wsl.conf is negligible considering everything else that is done during a WSL instance "boot".

@m00head
Copy link

m00head commented Aug 31, 2018

Fixed it by using the latest workaround based on this comment: #1493 (comment)

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{GUID}\Flags

Change Flags from 7 to 5 in order to exclude the WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH enum.

Now my path looks like this:
PATH="/home/<user>/.local/bin:/home/<user>/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

@mkarpoff
Copy link

@m00head The correct (through wsl configuration) is to edit the file /etc/wsl.conf in there put in the following line of code

appendWindowsPath=False

Then you have to relaunch ubuntu.
You can also change other things like enable meta data using settings in this file

@CyrusNajmabadi
Copy link

@MostafaOkasha

@CyrusNajmabadi The behavior you are describing matches Section: automount under Configuration Options here:

Unfortunately, i even see other windows $PATH entries with spaces placed in my bash path.

@CyrusNajmabadi @mkarpoff even if that would work, that's not a solution. We only need to exclude node/npm stuff, not everything.

I just don't want path entries added. I set appendWindowsPath to false, and it's simply not working.

@skalinets
Copy link

skalinets commented Mar 4, 2019

I just added export PATH="$PATH:/usr/bin" to the end of ~/.bashrc, so that usr/bin takes precedence over windows' apps.

@CyrusNajmabadi
Copy link

@MostafaOkasha I think there's a disconnect here:

  1. i do want drives mounted. I make use of this heavily.
  2. i do not want windows PATH entries added to the environment. Not only does it not help me with anything, but it actively breaks thigns on our end as the spaces you insert in the path break many tools that do not expect spaces there.

@m00head
Copy link

m00head commented Mar 8, 2019

@CyrusNajmabadi

I just don't want path entries added. I set appendWindowsPath to false, and it's simply not working.

You need to restart the WSL console window for it to pick up the new setting in wsl.conf - better still reboot your computer or restart your virtual machine.

Using Registry Editor, navigate to the following key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{GUID}\Flags

What is the WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH value set to? (assuming it is present)

Have you tried the registry workaround I posted here previously? #1493 (comment)

This ends up breaking several of our tools. I'm currently on 1809.

Which OS build version of Windows 10 1809 are you on? e.g. 17763.316
Which Windows operating system am I running? - Windows Help

@CyrusNajmabadi
Copy link

You need to restart the WSL console window for it to pick up the new setting in wsl.conf -

Done. It didn't help.

better still reboot your computer or restart your virtual machine.

Didn't help.

These are the only values set:

image

Have you tried the registry workaround I posted here previously? #1493 (comment)

I have not. SHouldn't wsl.conf work here?

Which OS build version

I'm on this:

image

@m00head
Copy link

m00head commented Mar 12, 2019

@CyrusNajmabadi

Have you tried the registry workaround I posted here previously? #1493 (comment)

I have not. Shouldn't wsl.conf work here?

Setting appendWindowsPath to false in your wsl.conf file doesn't seem to be working for you - the Flags registry value should be changed from 7 to 5 as a result.

This may be because the location of your wsl.conf file is not correct, or the file is corrupt.

You should NOT edit this file from Windows because this will cause it to become corrupted (see #1662 and #3536)

Instead, edit the file from within the WSL console window using nano or vi:
/etc/wsl.conf

Otherwise, try changing it manually from 7 to 5, then restart the WSL console window.

@maxsu
Copy link

maxsu commented Jun 20, 2019

What's the status on wsl.conf for (not-insider) Build 17134 and friends?

I am by all means updating to insider build, as this seems like part of WSL best practices for now. But it would be nice for a more out of box experience (for clueless users such as your truly.)

Side note: For those arriving from this Stack/Exchange post looking for a registry hack - setting appendWindowsPath in wsl.conf is the cleaner solution.

Looks like the wsl docs' Distro Management Section should have been my go-to. The docs are clean + well written, and mention Insider Build, wsl.conf and appendWindowsPath.

@ghost
Copy link

ghost commented Jan 31, 2020

After configuring wsl.conf

[Interop]
appendWindowsPath = False

don't forget to open Powershell (as administrator) and put this command:

Restart-Service LxssManager

Windows-10 1809

@SaeedShariati
Copy link

SaeedShariati commented Jul 10, 2020

I just installed wsl2 and now the flag's value is 15, not 7. what should I do?
edit: nvm making wsl.conf file worked(even though I couldn't restart the service, it still worked)

@benhillis
Copy link
Member

@SaeedShariati - use the /etc/wsl.conf method. The registry key method is unsupported.

@santiagoluz
Copy link

don't forget to open Powershell and put this command:

Restart-Service LxssManager

Thanks @ChinouneMehdi

Note that you need to execute PowerShell as Administrator in order to be able to restart this service.

@adamralph
Copy link

Has the method to do this been documented anywhere?

@syleishere
Copy link

syleishere commented Jan 21, 2021

#To remove windows paths:
echo 'appendWindowsPath=False' > /etc/wls.conf

in .bash_profile add:
alias wsl='/mnt/c/Windows/System32/wsl.exe'

then to restart it simple as:
source .bash_profile (only need this if didn't log back in)
wsl --shutdown

(then just reconnect)
If your using wls2 I assume your doing app development so these are also useful:
pico .bash_profile (modify accordingly)

#make sure to install pulseaudio on windows side, works great for kivy/python development
#may require patches under wsl2 to work correctly
export PULSE_SERVER=tcp:192.168.0.74
export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0.0
export EDITOR=nano
alias adb=/mnt/c/Users/dan/AppData/Local/Android/sdk/platform-tools/adb.exe
alias wsl=/mnt/c/Windows/System32/wsl.exe
alias pico='nano -w'
export PATH="/home/dan/src/flutter/bin:/home/dan/src/flutter/bin/cache/dart-sdk/bin:$PATH"

then you can just do things like connect your pixel 4xl device and do things like:
adb shell (use windows adb)
flutter upgrade
dart ./somefile.dart

Personally I have 2 copies of flutter on windows side and kali linux wsl2 side one in c:/src/flutter and one in ~/src/flutter
Personally I just use securecrt for connecting to my wls2 instance and other ssh instances.
Personally I just use paid version of xming for Xserver as non-paid one won't work properly with sending GUI's back to windows.
Personally my coding editors are android studio, visual studio code and pycharm, and nano while on unix terminal.

don't forget to add to .nanorc
set tabsize 4

So you can tab to 4 spaces while editting code and add your color syntax highlighting.

@adamralph
Copy link

Has the method to do this been documented anywhere?

I guess the answer is no.

@syleishere
Copy link

echo 'appendWindowsPath=False' > /etc/wls.conf
/mnt/c/Windows/System32/wsl.exe --shutdown

@Aschay
Copy link

Aschay commented Mar 12, 2021

This happened to me after installing nvm ! Please document the right answer .
here is what worked for me :
1.At runtime add for the .bashrc with
PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')
2.Changing the configuration of wsl2 with
sudo touch etc/wsl.config sudo vim etc/wsl.config
and adding this to it
[interop] enabled=false appendWindowsPath=false
dont forget to restart your distribution on method 2 , wsl --shutdown then wsl.exe

@iuliandita
Copy link

I just changed the Flags in the registry and my Ubuntu WSL is completely gone. Reset.

I got this message:
image

The VHDX file with the disk drive has been completely erased. The folder C:\Users<user>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState is empty.

I think I am going to pass out...
All my files are gone. All the code was committed, but my notes and my dotfiles are gone, all the hours spent setting up the environment, wasted... WT actual F??

The initial flag value was 15. I did test it out again, after setting up a new ubuntu wsl, and the same thing happened.

@liudonghua123
Copy link

After configuring wsl.conf

[Interop]
appendWindowsPath = False

don't forget to open Powershell (as administrator) and put this command:

Restart-Service LxssManager

Windows-10 1809

I use wsl --terminate distribution-name(eg wsl --terminate kali-linux) instead of Restart-Service LxssManager

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

No branches or pull requests