简体   繁体   中英

How do I link an application to usr/local/bin so I can call it globally in the terminal. Mac

I installed a new code editor. Sublime 3. I want to be able to open Sublime from the command terminal so I can use commands like

Editor .

To open a code project whose directory I am in.

To do this I tried linking the Sublime App to my 'usr/local/bin' in the following ways.

ln -s /Applications/Sublime Text.app /usr/local/bin
ln -s /Applications/Sublime Text /usr/local/bin

'Sublime' now shows up in the '/usr/local/bin' directory, however the following commands don't work.

cd /path/code_folder
Sublime . 
Sublime Text.app . 
Sublime Text . 

They all return

-bash: Sublime: command not found

You linked to the wrong thing. Sublime Text.app is really a directory, you want to symlink to the actual binary:

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

This is almost a verbatim copy/paste from the documentation . I kept the name subl though you could obviously easily use a different name.

Notice also the correct use of quotes; you created a symlink Text.app and another called Sublime , neither of which currently points to a valid location. See also When to wrap quotes around a shell variable?

Download Sublime Text for Mac.

In your Downloads directory, double-click on Sublime Text.dmg to open it.

Drag Submlime Text 2.app into your Applications folder.

Run below command in your terminal.

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

Now open file in current directory using subl filename.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM