Vik
Vik

Reputation: 415

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

Upvotes: 4

Views: 3043

Answers (2)

Nicolas Hypolite
Nicolas Hypolite

Reputation: 1

I think that's what you wish you had.

That automaticly convert your Windows PATH to Bashrc:

https://github.com/hypolas/wintobashpath

https://github.com/hypolas/wintobashpath/releases/tag/v1.0.0

echo %PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\PowerShell\7\;C:\Program Files\nodejs;;E:\Program Files\Git\cmd;C:\Program Files\Go\bin;C:\Users\hypolas\AppData\Local\Microsoft\WindowsApps;C:\Users\hypolas\AppData\Local\Programs\Microsoft VS Code\bin;E:\msys64-2023\mingw64\bin;C:\Users\hypolas\AppData\Roaming\npm;C:\Users\hypolas\go\bin

Became:

/mingw64/bin:/usr/bin:/c/Users/hypolas/bin:/c/Users/hypolas/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/usr/bin:/mingw64/bin:/usr/bin:/c/Users/hypolas/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/dotnet:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/PowerShell/7:/c/Program Files/nodejs

I do that for myself.

Upvotes: 0

Rich Turner
Rich Turner

Reputation: 10984

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

Upvotes: 5

Related Questions