0

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 2.app/Contents/SharedSupport/bin/subl" ~/bin/sublime

And also this variant:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime

In the terminal, if I type in:

echo $PATH

I get:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

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.

1

3 Answers 3

6

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

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /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\ 2.app/Contents/SharedSupport/bin/subl /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\ 2.app/Contents/SharedSupport/bin/subl
2
  • 1
    Thank you for taking the time to respond. I think your solution is spot on, but the problem was that we weren't removing the old symlink I had created using the official Sublime Text site recommendation. At least, that's how I understand it. Aug 21, 2015 at 16:07
  • 1
    Nearly 3 years later this answer sorted the issue for me as well. The quoted version of ln -s as provided by the instructions weren't working for me, switching to the backslashed/escaped version as well as using sudo solved everything perfectly.
    – Scott
    Jul 31, 2017 at 8:48
-1

This should be a very simple thing, with the built in open command --

open -a "Sublime Text 2"

You can also create a sublime command alias for that.

alias sublime='open -a "Sublime Text 2"'
0
-1

I've done this so many times that I recommend:

  1. adding an alias to ~/.bashrc or ~/.zshrc (alias sublime="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl")
  2. moving that RC file to iCloud Drive, and symlinking that file back into your root ~

ln -s "/Users/username/Library/Mobile Documents/com~apple~CloudDocs/.zshrc" ~/.zshrc


if you use zsh, you can export icloud="/Users/username/Library/Mobile Documents/com~apple~CloudDocs"

1
  • “moving that RC file to iCloud Drive, and symlinking that file back into your root ~” Why? Why add “the cloud” to a simply alias/symlink? Dec 7, 2019 at 2:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .