Maybe I should be more embarrassed to admit this, but I always kind of just pray to god when I install CLIs, and it usually works. But I recently go a new computer, so I’ve had to install a lot of things, and as I’m following the install instructions for Sublime 3’s CLI for OS X, I read this:
The first task is to make a symlink to subl. Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin directory in your path, you can run:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Now I’d like to say I’m not guilty of copy and pasting things I don’t fully understand, but sometimes there’s only so much space in this brain. It looks like we’re making a symlink from the
subl file that comes packaged with Sublime 3 to
~/bin, where we’ll be able to execute it from the command line, which feels familiar enough. So I
mkdir bin and copy/paste their command and get command not found.
And then I’m like, yeah, maybe I don't really know what's going on here. Also don't I sometimes put this stuff in
So I did some research and took a look at the file system hierarchy manual page by running
man hier, and boy howdy, we’ve got some confusing duplicate directory names:
The modern OS X file system:
/Root directory of the filesystem
/binUser utilities fundamental to both single-user and multi-user environments
/etcSystem configuration files
/mach_kernelKernel executable (the operating system loaded into memory at boot time)
/sbinSystem programs and administration utilities fundamental to both single-user and multi-user environments
/usrSystem-wide, read-only files. All installed software goes here.
/binCommon utilities, programming tools, and applications provided by the OS.
/libArchive libraries provided by the OS.
/localSystem-wide, read-only files, but only the ones provided by the user i.e. you.
So, executables and libraries provided by the OS are going to be in
/usr/lib. Anything in addition to that we want to install system-wide and that should be available for all users should go in
/usr/local, and executables (like the sublime CLI I was trying symlink) should go in
So, I could edit the original command to install the Sublime CLI to this:
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
But if we take a closer look at the original Sublime command, they're pointing to
~/bin, which is shorthand for
/Users/<username>/bin. It's a common convention to store executables that only need to be available to the current user here, and better practice to avoid using sudo and installing things at the root when we don't need to. But in order to use it, I need to add
$HOME/bin) to my path variable (which is a list of directories where executables are stored) by editing my
.bash_profile to include:
Now running original Sublime command will work as intended. And voila! Now I can
subl to my heart’s content, and even better, I understand a little more about what’s going on in my
Side note: For some history into why there’s a
/lib in both
/usr, I recommend checking out this post by Rob Landley from 2010. Spoiler alert, it’s a holdover from working around limited disk space, and it isn’t a reason anymore! Explanations for the continued existence of this split have been repeatedly made in retrospect! If that doesn’t make you feel better about yourself as a developer, I don’t know what will.
Don't leave yet
Level up every day