Search code examples
windowsbashshellubuntuwindows-subsystem-for-linux

Keep the Path between Windows and 'Bash on Ubuntu on Windows' in sync


What's the best way to keep the Windows 10 Path and the 'Bash on Ubuntu on Windows (WSL)' Path in sync?

I have appended the Windows 10 Path (converted it to bash compatible) to .bashrc but the bash shell doesn't appear to be picking it up.

Steps I took:

  1. Get Windows Path >echo %PATH%
  2. Pick the relevant paths and convert to bash compatible (e.g. C:\Java becomes /mnt/c/Java )
  3. Start bash & edit .bashrc
  4. Append to .bashrc e.g.> export PATH=${PATH}:/bin:/mnt/c/Java/bin:/mnt/c/node

Solution

  • As of Insider build 145963 (ish), you don't need to append the Windows path in your .bashrc:

    In subsequent builds, and from Creators Update onwards, WSL automatically appends the Windows path to your Bash path, allowing you to launch Windows executables from within Bash without needing to enter the absolute folder location to executables that are on the path.

    For example, navigate to a temp folder on your C: drive, create a text file and open it in notepad:

    $ cd /mnt/c/temp
    $ echo Hello > hello.txt
    $ Notepad.exe ./hello.txt
    

    Tip: Don't forget the .exe extension - that's what tells Linux to ask WSL to launch the .exe