Open Sublime Text From WSL: Step-by-Step Guide
In this article
Yes, you can open Sublime Text from a WSL terminal in Windows, and the cleanest way is to add a small shell function or alias that calls the Windows executable directly. WSL can launch any Windows program through interop, so once the path to subl.exe is reachable from your Linux shell, typing subl . or subl file.txt will open the file in Sublime Text on the Windows desktop. The catch is that the path must be the Windows executable, not a Linux binary, and you must pass Windows-style paths or let a wrapper convert them for you.
This guide covers the manual setup, the path conversion problem, and the fixes for the cases where the command silently fails or opens an empty window.
What You'll Need
- Windows 10 or Windows 11 with WSL installed (WSL 1 or WSL 2 both work for this).
- Sublime Text installed on Windows. The default install location is
C:\Program Files\Sublime Text\subl.exe, though the folder name may differ slightly by version. - A WSL distribution with a shell such as Bash or Zsh.
- Interop enabled. It is on by default, but if Windows executables cannot run from WSL at all, check
/etc/wsl.conffor aninteropsetting that disables it.
Step-by-Step
- Confirm Sublime Text's Windows path. In Windows, open File Explorer and go to
C:\Program Files\Sublime Text\. Look forsubl.exe. If the folder has a version number in it, note the exact name. If you installed Sublime Text somewhere else, use that path instead. - Test the executable from WSL. Open your WSL terminal and run the full path with the
.exeextension. In WSL, Windows drives appear under/mnt, so the command looks like this:/mnt/c/Program\ Files/Sublime\ Text/subl.exe --versionThe backslash before the space escapes it. If a version string prints, interop and the path are both working. If you get "No such file or directory", recheck the folder name in step 1.
- Create a wrapper function. Calling the long path every time is impractical, and a plain alias is not enough because you also need to convert Linux paths to Windows paths. Add a function to your shell config file, either
~/.bashrcfor Bash or~/.zshrcfor Zsh:subl() { /mnt/c/Program\ Files/Sublime\ Text/subl.exe "$(wslpath -w "$1")"; }This uses
wslpath -w, a built-in WSL utility that converts a Linux path into a Windows path. Sublime Text on Windows cannot open/home/you/file.txtbecause that path does not exist from Windows' point of view; it needs\\wsl.localhost\...or a mapped drive path, which is exactly whatwslpathproduces. - Reload your shell config. Run
source ~/.bashrcorsource ~/.zshrc, or simply close and reopen the terminal, so the function is registered. - Test it on a file. Move into a project directory and run
subl .to open the current folder, orsubl notes.txtto open a single file. Sublime Text should appear on the Windows desktop with the file loaded. - Handle multiple arguments if you need them. The simple function above only converts the first argument. If you routinely open several files at once, use a loop instead:
subl() { local args=(); for f in "$@"; do args+=("$(wslpath -w "$f")"); done; /mnt/c/Program\ Files/Sublime\ Text/subl.exe "${args[@]}"; }This converts every argument before passing them along, so
subl a.txt b.txtworks as expected. - Optional: make it available for other tools. Many command-line tools look for an editor through the
EDITORorVISUALenvironment variable. Settingexport EDITOR=sublin the same config file lets tools such as git open Sublime Text when they need an editor. Note that tools waiting on the editor may behave oddly, because the Windows process returns immediately while the window stays open.
Common Mistakes
- Calling
sublwithout.exe. WSL does not automatically append extensions for Windows programs the way Windows does. Usesubl.exein the function body. - Forgetting to escape the space.
/mnt/c/Program Files/...is split into two arguments by the shell. Quote the whole path or escape the space. - Passing Linux paths unchanged. This is the most frequent failure. Sublime Text opens, but the file is missing or a blank tab appears, because Windows cannot resolve
/home/.... Always route paths throughwslpath -w. - Putting the function in the wrong file. If you use Zsh but edit
~/.bashrc, the function never loads. Match the config file to your actual shell. - Using a symlink to the executable. Symlinking a Windows
.exeinto a Linuxbindirectory often fails. Call the real path inside the function instead.
Tips
- Keep projects on the Linux filesystem (
/home/you/...) for speed, and let the wrapper handle the conversion. Editing files stored under/mnt/cfrom WSL is slower. - If you prefer a shorter command name, rename the function, for example
st(), but keepsublas well since many tutorials assume it. - Run
wslpath -w .on its own to see exactly what Windows path your current directory maps to. It is a quick way to debug conversion problems. - If your Sublime Text install folder includes a version number, update the function path once after any upgrade rather than editing it each time you open a file.
Troubleshooting
The command is not found. The function was not loaded. Confirm which config file your shell reads, then run source on it and try again. Also check that you are not in a fresh shell that has not picked up the change.
"No such file or directory" on the executable path. The folder name is wrong. List the directory with ls "/mnt/c/Program Files/" and copy the exact Sublime Text folder name.
Sublime Text opens but the file is empty or a new blank tab appears. The path was not converted. Test by running the executable manually with a converted path from wslpath -w; if that works, your function is not being used, likely because an alias or another definition with the same name takes precedence.
Nothing happens at all. Interop may be disabled. Check /etc/wsl.conf and confirm there is no enabled=false under an interop section. After editing that file, a full WSL restart is required, which you can do from Windows with wsl --shutdown.
It works for files but not folders. Some setups fail when the argument is a directory rather than a file. Confirm the folder exists and try the absolute path instead of ..
Permission or mount errors. If /mnt/c is not mounted, Windows drives are unavailable to WSL. Restart WSL and check that automount is enabled in /etc/wsl.conf.
Frequently Asked Questions
Can I just use subl without any setup?
Only if something already provides it. WSL does not ship a subl command, so you need to create the function or alias yourself.
Why does the Windows executable path start with /mnt/c?
WSL mounts Windows drives under /mnt by default, so the C: drive is reachable at /mnt/c. Other drives follow the same pattern.
Does this work with WSL 1 as well as WSL 2?
Yes. Both versions support running Windows executables, and both provide wslpath for path conversion.
Will changes I make in Sublime Text save back to the WSL file?
Yes. Sublime Text edits the file through the Windows path that points back into the WSL filesystem, so saves land in the same Linux file.
Can I set Sublime Text as my default git editor this way?
You can set EDITOR=subl, but be aware that git may not wait for the Windows window to close, since the launched process returns immediately. If commit messages get skipped, use a terminal editor for git instead.
Do I need to reinstall anything after a Sublime Text update?
No. Just check whether the install folder name changed and update the path in your function if it did.