Using Windows Subsystem for Linux (WSL) from Sublime Text Using Windows Subsystem for Linux (WSL) from Sublime Text windows windows

Using Windows Subsystem for Linux (WSL) from Sublime Text


  1. You have to copy the C:\Windows\System32\bash.exe file to the C:\Windows\SysWOW64\ directory.Required because of the WoW64 file system redirection (Thanks Martin!)

  2. Then you have to create a new build system in the Sublime Text with the following code. (Tools -> Build System -> New Build System...)

    {  "cmd" : ["bash", "-c", "gcc ${file_name} -o ${file_base_name} && ./${file_base_name}"],  "shell": true,  "working_dir": "${file_path}",}

    This code will complile the .c code and than run it. The output will be shown in the Sublime's Build Results panel.

  3. When you want to use this Build System, select it in the Tools -> Build System list, then hit Ctrl + B.

You can customize the command I put there, the main thing is that you can run Linux commands using bash -c "CommandsYouWantToRun"


In WSL2, the best possible way according to me is using the below sublime-build file.

  • You have to create a new build system in the Sublime Text with the following code.
    (Tools -> Build System -> New Build System...)
    {    "shell_cmd": "ubuntu run \"g++ `wslpath '${file}'` && ./a.out<inp.in>out.in \" ",    "shell":true,    "working_dir":"$file_path",    "selector":"$file_name"    }
  • This code will complile the .cpp code and use inp.in and out.in as input and output files respectively (Optional, if you don't want that, then replace ./a.out<inp.in>out.in with ./a.out). The output will be shown in the Sublime's Build Results panel.

  • When you want to use this Build System, select it in the Tools -> Build System list, then hit Ctrl + B.


On WSL 2 the suggested solution doesn't work. Here is a solution to execute on a WSL 2 target a script edited in Sublime Text on Windows. Create a bash-wsl.sublime-build file:

{    "shell_cmd": "bash -c \"wslpath '${file}'\" | bash -s",    "shell": true,}