Remove Windows executables from your WSL Linux path
Windows and WSL interoperability is fantastic but sometimes you end up with unintended side effects. When coding I like to have specific tools and configurations for each environment. Otherwise, I can get pathing or other problems. Why is it complaining about a '\r' character when I'm running Linux? It is because some Linux tools and Windows files collide with each other.
With that in mind, you may wish to remove the Windows executables from your Linux $PATH. There are two ways to configure the WSL to not import the Windows $PATH.
- You can disable or enable it on a per WSL instance basis.
- You can globally configure WSL so that the PATHbehavior is the same for all WSL instances you have configured.
Configuring individual WSL instances with wsl.conf
Each individual WSL instance looks in its own configuration file /etc/wsl.conf that may not be created by default in your WSL instance.
1. Edit the existing /etc/wsl.conf . Create a new wsl.conf file in /etc if one doesn't already exist.
1. Add the following section to /etc/wsl.conf
[interop]
appendWindowsPath = false
wsl.conf's interop section can contain other settings other settings. They are outside of the scope of this discussion. You can read up on them at documented in https://learn.microsoft.com/en-us/windows/wsl/wsl-config#example-wslconf-file
# Set whether WSL supports interop processes like launching Windows apps and adding path variables. Setting these to false will block the launch Windows processes and block adding $PATH environment variables
[interop]
enabled = false
appendWindowsPath = false
Configuring all WSL instances identically using .wslconfig
You can configure interop and other properties globally, across all WSL instances on this physical machine.
Global WSL configuration can be shared across all WSL instances on a machine .wslconfig stored in your Microsoft Windows home directory. See https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig The WSL user's home directory is defined in %UserProfile% . It is typically something like /Users/<username>.
Ex: Joe is a Windows and WSL user whose Windows home directory is in c:/Users/Joe. The full path to .wslconfig would be C:/Users/Joe/.wslconfig.
References
- https://github.com/microsoft/WSL/issues/4234
- https://learn.microsoft.com/en-us/windows/wsl/wsl-config
- https://learn.microsoft.com/en-us/windows/wsl/wsl-config#global-configuration-options-with-wslconfig
- https://docs.flutter.dev/get-started/install/linux
Revision History
2023/10 Created
Comments
Post a Comment