MacOS – How to add link to Sublime Text

macossublimetextterminaltext-editor

Just installed fresh copy of El Capitan and as usual started to install stuff… And suddenly faced strange problem. I'm using Sublime Text. It provides bin called subl, which allow to use it from console. So I added link to it like:

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

But when I try tuo use it from console i get:

MacBook-Pro-Kiril:~ $ subl
-bash: subl: command not found
MacBook-Pro-Kiril:~ $ ls /usr/loca/bin
ls: /usr/loca/bin: No such file or directory
MacBook-Pro-Kiril:~ $ ls /usr/local/bin
brew        mongo       mongodump   mongofiles  mongooplog  mongorestore    mongosniff  mongotop    npm
bsondump    mongod      mongoexport mongoimport mongoperf   mongos      mongostat   node        subl
MacBook-Pro-Kiril:~ $ ls /usr/local/bin/subl
/usr/local/bin/subl
MacBook-Pro-Kiril:~ $ ls -la /usr/local/bin/subl
lrwxr-xr-x  1   admin  63 Oct 28 19:42 /usr/local/bin/subl -> /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
MacBook-Pro-Kiril:~ $ mongo
MongoDB shell version: 3.0.7
connecting to: test
2015-10-28T20:22:18.219+0200 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-10-28T20:22:18.221+0200 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
MacBook-Pro-Kiril:~ $ which mongo
/usr/local/bin/mongo

As you can see other tuff from /usr/local/bin works fine. I also tried just for test create copy of nano and it worked fine…

MacBook-Pro-Kiril:~ $ nano
MacBook-Pro-Kiril:~ $ which nano
/usr/bin/nano
MacBook-Pro-Kiril:~ $ ln -s /usr/bin/nano /usr/local/bin/nano_2
MacBook-Pro-Kiril:~ $ nano_2
MacBook-Pro-Kiril:~ $ rm /usr/local/bin/nano_2
MacBook-Pro-Kiril:~ $ nano_2
-bash: /usr/local/bin/nano_2: No such file or directory 

Best Answer

Use one of the two forms shown below:

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

Or:

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

But do not mix both using quotes and backslashes to escape spaces.