MacOS – Having trouble creating symlink between the terminal in Mac OS X and Sublime Text 2 so it can be launched from the command line


I’m using Mac OS X Yosemite and I want to be able to open Sublime Text 2 from the terminal with a command like this:

sublime .

I’ve typed this into terminal as shown on the Sublime Text 2 website:

ln -s "/Applications/Sublime Text" ~/bin/sublime

And also this variant:

ln -s "/Applications/Sublime" /usr/local/bin/sublime

In the terminal, if I type in:

echo $PATH

I get:


I’ve tried editing my .bash_profile, right now it’s blank

After all this, I try sublime . and get the following error:

-bash: sublime: command not found

I’m completely new to Mac OS X, and terminal configuration, and am really struggling to figure out why I can't get it to work so any help would be appreciated.

Best Answer

Try running the back-slashed/escaped version of the ln -s command as explained here like so:

ln -s /Applications/Sublime\ Text\ /usr/local/bin/sublime

As that site explains—and I concur—the ~/bin that the official Sublime Text site recommends just seems weird and I have never encountered a recommendation like that for local binaries before. So avoid using it.

But what is also weird in all examples is that sudo is not being used. That /usr/local/bin directory is a root system directory and is not normally writable by anyone but root. So with that in mind just run the above command via sudo like this:

sudo ln -s /Applications/Sublime\ Text\ /usr/local/bin/sublime

Of course you will now have to enter your root/administrator password. But once that is done the symbolic link should be in place. And to confirm it’s there just run this command from the terminal:

ls -la /usr/local/bin/sublime

The output should be a directory listing with dates/times that looks something like the following:

lrwxr-xr-x   1 root  wheel       27 Aug 21  2015 sublime -> /Applications/Sublime\ Text\
Related Question