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.

  1. You can disable or enable it on a per WSL instance basis. 
  2. 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

appendWindowsPath = false

wsl.conf'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

# 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

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



Revision History

2023/10 Created


Popular posts from this blog

Understanding your WSL2 RAM and swap - Changing the default 50%-25%

Installing the RNDIS driver on Windows 11 to use USB Raspberry Pi as network attached

DNS for Azure Point to Site (P2S) VPN - getting the internal IPs