-
Notifications
You must be signed in to change notification settings - Fork 823
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
Problems with Windows PATH variable getting imported #1890
Comments
@mindplay-dk - Thanks for posting. You bring up many valid concerns, which is why I added the global opt-out registry key in the first place. We initially flighted this feature in Insider builds and I was fully prepared to pull the ripcord on this feature if a lot of people were having issues with it. However, my experience was much the opposite and most of the feedback has been overwhelmingly positive. I know a registry key isn't a very elegant solution and in the future different configuration options like this will be exposed in a more discoverable and user friendly-way. Alternatively you can also override your $PATH variable inside of your .bashrc file. Let me try to address some of the specific issues you bring up:
Lastly I appreciate the feedback! I'm very proud of my work lighting up interop but know it isn't perfect. Regarding the feature's usefulness I will defer to our User Voice where this was one of the highest requested features. |
Okay, if that's what people want, I suppose there's no arguing with that :-) And I'm not "against" this feature per se, I just find it confusing, perhaps because I think more of UOW as being a tool that enables me to comfortably run Linux tools with closer integration to Windows compared with Docker or an emulator - I guess some people (possibly the majority) may think of it more as better alternative to Git Bash in that it also happens to run Linux binaries. I guess the latter mode of thinking is what you inspire by naming it "Bash on Windows" :-)
Yeah, it kind of comes back to your next comment:
True, but most tools these days are not in fact binaries - Of these, at least The oddest thing about the Node-related issues, was that some Replacing any globally-installed node/gyp/node-sass packages on my Windows drive obviously would be very bad if I ever try to run any of it from a plain Windows shell again, so I ended up creating a Linux install of node/npm/gyp anyway. But even if I avoid global package installations and install locally in Anyhow, overriding the I guess you can close this issue, though I'll just put one thought out there: maybe importing some paths, such as |
@benhillis - It is kind of an existential question WSL will have to face eventually. It isn't just Node.js. Say you are a Java programmer. You have the same kind of problems as @mindplay-dk's quote above. Did you mean Java backed by a bunch of win32 native libraries built with msvc? Or Java backed by a bunch of Linux native libraries built with gcc? Ditto Python, which is what the guy over in #1370 is struggling with presently. I am sure you have a handle on all this in your head. +1 for the pure awesomeness that is WSL interop. But it is going to be rough sailing with a lot of confusion for while. |
@mindplay-dk -- I think you've missed a point about binaries, and as such have not entirely answered @benhillis 's question. Namely: In Windows, if it doesn't have a file extension, it ain't gonna run :-) It may be a As a result, something like So what you're telling us is that you have a Windows application that is creating scripts that are not valid Windows scripts, and putting them in Windows %PATH%. That's just weird :-) To me, the obvious follow-up questions are (1) which app, and what scripts?, and (2) why is it doing that? |
Well, usually, the way these things are wired on Windows, there's an auto-generated I believe tools such as Composer do that as a work-around, so that end-users don't have to hand-write a Is it weird that the Perhaps one reason they keep it that way, is so that e.g. Git Bash (which I have been using for a long time) will actually skip the |
aaand, there you are :-) |
And here's npm doing a similar thing - it uses this package to do it. Likely package managers for other scripting languages (ruby, perl, python) are doing similar things? |
Hm -- that's a good point, and I think a good use case. I haven't run into this with Python (which I use a bunch personally), perhaps because it's slightly more common in Python-land to install as a module and invoke as (Your point about Windows and Linux local node installations conflicting is a good one, and has been made on other tickets before. It's particularly bad because even simple It seems to me that Windows can't directly execute these extension-less files, and Linux (meaning, code run within WSL) hasn't tried to mark them as executable. So perhaps this could be addressed in a future iteration of DrvFs, by not setting the execute flag on files in that case? Just a thought -- Linux tools will generally ignore files in $PATH if they aren't marked as executable. |
I think this bug is giving me Python issues. Currently trying to set up the ebcli in WSL; pip installs it fine, but when I try to run something like
It looks like the Windows Python path is beating the one I set in |
Looks like the same problem I was having. Lots of package & script bins don't have file extensions, so the Win version might get executed if it gets found first. Some people fix it by pre-pending their Linux entries to the PATH var so they always come first, but I think sometimes it's better to remove competing Win paths (especially when they provide identical function.) I added this to my Function Source: Removing a directory from PATH ### remove unnecessary Win PATHs
# This can prevent extension-less commands from bleeding into BASH.
# (eg. "ng" would execute the Win bin if "@angular/cli" wasn't installed on Linux.)
#
function path_remove {
# Delete path by parts so we can never accidentally remove sub paths
PATH=${PATH//":$1:"/":"} # delete any instances in the middle
PATH=${PATH/#"$1:"/} # delete any instance at the beginning
PATH=${PATH/%":$1"/} # delete any instance in the at the end
}
path_remove '/mnt/c/Users/me/AppData/Roaming/npm'
path_remove '/mnt/c/Users/me/AppData/Local/Yarn/bin'
path_remove '/mnt/c/Program Files (x86)/Yarn/bin'
path_remove '/mnt/c/Program Files/Git'
path_remove '/mnt/c/Program Files/Git/cmd'
path_remove '/mnt/c/Program Files/nodejs'
path_remove '/mnt/c/OpenSSL-Win32/bin'
path_remove '/mnt/c/Program Files (x86)/Python27' @john-osullivan I noticed that with |
I just started looking at the Windows Subsystem for Linux feature now. I had this issue with Node.js and npm. As stated by @mindplay-dk in the top post, I disabled the Path import feature using the registry key. To clarify for anyone having the same problem. Disable the feature by closing the bash shell, create the DWORD registry key, run the bash shell. If you then type I agree with @mindplay-dk, this seems like a backward feature. I think it depends on where you are coming from. I have been working with Linux for many years and do not expect windows binaries in my Linux path. I imagine people who have mostly worked with Windows would expect to be able to run This should be an Opt-in rather than an Opt-out feature. |
@grantcarthew - I think you nailed it, it depends on where you are coming from. I hear all the time that having NT paths imported to WSL is peoples favorite feature and they love it. Conversely, I also hear from others that it breaks their makefiles or other scenarios. I think the problem is these features are hidden behind some not very well documented registry keys. I'll create a work item to come up with a better way to set up various WSL configuration options. Thanks for the feedback. |
Just ran into this issue myself where running npm and nodejs were picking up the windows versions - modified the bashrc to fix it - But took me some figuring out before fixing it which lead me here - Just writing to +1 on making it better configurable - as it's not something I was expecting to come across. Not per say an issue: Other then turning WSL on in windows - thats the only option I know exists for it. |
Can confirm that both n-install AND rbenv suffer from this problem |
Suffering the same issues as everyone else while trying to use Nodejs. IMO it's not worth polluting PATH in Linux just so we can run Windows apps. Managing PATH manually via bashrc seems like it could get tedious. I heard there's a registry switch for it and will probably use that but I feel strongly there should be an option to turn it on, but have it turned off by default. As others have said, it's not rare in Windows to have a command that's exactly the same as it's Linux counterpart. |
So, can you add an alias in I think I have made a mess because I have installed Is there a solution to this? I'm thinking about doing another install of WSL via the Windows insiders channel, I had it switched on as a beta feature before |
Alternatively to the |
My machine has gone off for an RMA now so I'll have a fresh and clean install to play with when it comes back 😄 |
|
I ran into an issue with the Windows path in my bash environment twice. The second issue was a makefile getting confused on a path that contained embedded parentheses and spaces. While these are legal in Linux filesystems, they are rarely used. The correct fix was in the makefile. The first issue was more insidious. I had Strawberry Perl on my Windows path. It's built with MinGW. Because Perl allows C interop, Strawberry Perl includes the MinGW C++ stdlib. I also have GCC on my Ubuntu install. GCC just searches the path for a compatible stdlib. When compiling I found that GCC would pick up the MinGW stdlib, which looks like a GCC stdlib, because it was first on the path. The fix was to switch to ActiveState Perl : ) I run one node.js app on WSL (Matt Godbolt's Compiler Explorer) and haven't seen any weird issues with node. |
The ability to disable this behavior via wsl.conf has been added to build 17713. https://docs.microsoft.com/en-us/windows/wsl/wsl-config#interop |
@benhillis IMO this should be disabled by default. Simply importing the Windows path and expecting meaningful results is a little bit bonkers - even if that works some of the time, for certain things, the results are pretty random, since there's no guarantee that if/when something works, it works for the right reasons. For example, I just realized Linux has been picking up my Composer global bin-folder and running scripts I installer under Windows with a different version of PHP under Linux - obviously, it has all the wrong dependencies installed, for the wrong version of PHP, and eventually failed hard. Same would be the case for Node, Python scripts, etc. - just passing paths from the Windows environment to the Linux environment and expecting meaningful results is a little bit naive, isn't it? |
@mindplay-dk Try this to see if it can work for you: |
@molxyz thanks, for now I'm working around this by prepending my Linux search-paths to make sure they "win" over the imported Windows paths - I understand there's an option to disabled this feature in the next version anyhow. |
@mindplay-dk Ah cool.. I'm using Ubuntu 18 Bionic. I hope Ubuntu will have this option, great to hear. Thank you. |
Just wanted to leave a note here for future devs 👩🚀 -- if you get rid of your Windows path imports in WSL via any of the above mentioned methods, it seems to break some functionality like launching a Storybook on a local sever. Just a heads up 👍🏽 |
I personally have not had any issues at all with this. My tools installed in wsl will always take precedence over a windows one. eg. composer in wsl will only run the linux version. I have to type composer.exe to run the windows one. As to why this is an advantage one example I'd give is that git in linux can use the windows git credentials manager with native windows secure credential storage while still having its own configs separate form git in windows. |
You can also run it from # Run from bash from WSL2
danon@desktop:~$ npm -h
bash: ./mnt/c/Program Files/node.js/npm: No such file or directory
# Run through cmd
danon@desktop:~$ /mnt/c/Windows/System32/cmd.exe /C npm -h
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config, It's a little slower, but paths are guranteed to work, since it's actually Windows shell that runs it. |
Just add That was the only method that worked for me |
I'm siding 100% with @mindplay-dk on this issue. I just experienced problems with installing a framework on Windows and WSL simultanously, which caused the WSL to mix up the path variables (which are in turn used to install certain programs). This was unexpected behaviour to me and I would have thought that those environments would run more secluded. Also, I don't really see the benefit of this feature other that I can run explorer.exe or code . from the get go. I think it's more intuitive to hook up explorer.exe and other apps inside your .bashrc as an opt-in. I did this (as a recap):
/etc/wsl.conf:
This prevents wsl startup to append Windows paths to the linux path variable.
There should only be distro related paths now :) |
The name of this setting indicates the problem perhaps it should prepend not append. |
As was described here by @MartyMcFlyInTheSky, VSCode can be added as alias even when setting
This has a problem, though. VSCode will tell you:
But, if you set the alias like that: I know the thread is ancient, it's just that I had to do this exact thing myself recently and had to do a bit of googling and reading to find an answer, since having |
Just to update that @MartyMcFlyInTheSky helped me as well to fix this setup and add some more seperation between the two systems. # windows paths
alias code='/mnt/c/Program\ Files/Microsoft\ VS\ Code\ Insiders/bin/code-insiders' to my ~/.zshrc instead of the other path. PS C:\Users\user> where.exe code
C:\Program Files\Microsoft VS Code\bin\code
C:\Program Files\Microsoft VS Code\bin\code.cmd
PS C:\Users\user> where.exe code-insiders
C:\Program Files\Microsoft VS Code Insiders\bin\code-insiders
C:\Program Files\Microsoft VS Code Insiders\bin\code-insiders.cmd in powershell (windows) |
I understand that the Windows
PATH
variable gets imported into the Linux environment on start-up.I gather from poking through related issues that this is by design, I guess, with the idea of being able to run Windows executables from the Bash command prompt.
I was quit suprised to find that feature on the road-map. I honestly was not expecting that would be possible at all, and I'm not completely sure I understand how that's going to be useful in practice. I mean, even if they can launch, Windows applications aren't going to be aware of the Linux OS, so it seems a bit odd.
Either way, I find that the import of Windows paths into the Linux environment is causing a lot of practical problems.
For example,
node
andnpm
were immediately launchable from the Bash console, but I tried tonpm install node-sass
, which depends on a global installation ofnode-gyp
, which I have installed globally on on Windows, but these tools are hardware and OS dependent, so it all just sort of blows up in your face.Another example is
composer
, which was also immediately launchable from Bash, but I have plugins that cached various file-system paths in flat files with\
windows backslashes in the path, which caused errors. I have various tools installed globally, and I have the global Composer installation folder in my system path - simply importing that to Linux doesn't mean those tools will actually work.I have lots of scripts and tools set up for my work routine in Windows, and these simply don't work, or get in the way and cause weird/unexpected results in Linux.
I understand that there's a registry work-around which I guess I'll try, but I wanted to open this issue to make you aware that, well, there are issues with this feature. Things that were designed to run under Windows, built for Windows, installed on Windows, etc. often have artifacts like cached data or binaries that don't simply work, even if you can get them to launch under Linux.
I think this feature is going to confuse a lot of Windows users. As others have pointed out, the name "Bash on Windows" is kind of misleading, because the Bash terminal is just a tiny front-end to a very large and complex Linux system behind it - I at least understood and expected this, some Windows users may not, but I never expected a feature like this, and I'm not sure it's useful.
What's more, I spent like two hours drilling through Linux startup scripts to figure out where these path variables were being set in the first place, and didn't find it - I guess they're "hard injected" into the Linux subsystem somehow at startup? I suppose that's why there's a registry key to toggle this feature. I was trying hard to get into "Linux mode", and was expecting to find an initialization like this in e.g.
~/.bashrc
which I think is where thePATH
variable is normally initialized?Perhaps a better approach would be to inject the Windows path into a separate variable, e.g.
WINDOWS_PATH
, rather than injecting directly intoPATH
, and then initializePATH
in~/.bashrc
where I'd be able to see it and change it?The text was updated successfully, but these errors were encountered: