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.

5

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
  • 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. – Ryan Oliver Lanham Aug 21 '15 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. – Scottie Jul 31 '17 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"'
  • While this is useful for an application that doesn’t have it’s own built-in binary for easy Terminal use, Sublime Text does indeed have such a binary as explained in the question and answer as well as this page located in /Applications/Sublime Text2.app/Contents/SharedSupport/bin/subl. The question is about how to successfully create a symbolic link in the terminal from that binary to /usr/local/bin/sublime for easy access. – JakeGould Sep 10 '15 at 1:33
-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"

  • “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? – JakeGould Dec 7 '19 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.