I can't seem to figure out how to open Sublime Text 2 from Bash on Ubuntu on Windows. Ultimately I would like to be able to use subl .
to open the contents of the directory I am in.
On my machine, Sublime Text 2 is installed at C:\Program Files\Sublime Text 2
. sublime_text.exe
is located in this directory. In Bash on Ubuntu on Windows, I can access any files located on C
through /mnt/c/
.
I tried setting an alias: alias subl="/mnt/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"
. However, upon trying subl .
I get the following error:
cannot execute binary file: Exec format error
How can I set this up properly?
Open command prompt and type sysdm. In Advanced tab, select Environment variables. Under system variables, select variable named " Path " and click Edit . Add " C:\Program Files\Sublime Text; " to the end of the existing string. Save the changes and restart command prompt.
It's now possible to launch Windows executables (like Sublime Text) from the Bash on Ubuntu command line.
You should also be able to set an alias to use it from the command line (as you were trying to do). Mine is as follows (and works fine):
alias subl='"/mnt/c/Program Files/Sublime Text 3/subl.exe"'
Note the second set of quotes: this is necessary because of the spaces in the file path. Alternatively you can escape the spaces (as you did in your example).
Nick F's answer is correct, but there is an important caveat.
If your intent is to edit Linux files using Sublime Text, then you should reconsider. Doing so can cause data corruption, as I've discovered first hand.
See here for more details on why: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/
I realize this is an old post, but I'm hoping this will serve as a warning to other users attempting to set up Sublime Text to edit Linux files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With