I often write system-wide scripts and I wonder where to place my executables on macOS.

On many Linux system, /usr/local/bin (also /usr/local/sbin) is usually empty and I place my executables in there.
But on macOS, /usr/local/bin has already contained a lot of executables provided by such as Homebrew.
I understand /usr/local/bin is the most proper directory to place executables locally installed and similar questions also are answered /usr/local/bin, but I feel hesitant to contaminate by mixing my executables.
Is it good manner to place my executables in /usr/local/bin in spite of many other executables existing?

In other way, I am wondering where is the second best directory to place my executables.
I think /opt/bin is the second best at the moment because /opt/bin seems to proper directory to place my executables by its purpose and /opt/bin does not exist by default on macOS (empty assured).

Is there any idea or advice about my wondering?

similar questions (answered /usr/local/bin is best):

  • 1
    I like ~/.local/bin as described in the systemd file hierarchy, extending the XDG spec. Doesn't require special permissions, keeps ~ clutter free, but is still easy to find. – Benjamin W. Aug 6 '20 at 15:11
  • @BenjaminW. Thank you for your opinion! I have been using ~/.local/bin too for many years. I agree completely that this is smart way for personal use executables. But I wondered where to place system-wide my executables. – Hironobu Nagaya Aug 6 '20 at 15:34
  • Oh, system wide, right! Symlinks into /usr/local/bin is what I do for that. – Benjamin W. Aug 6 '20 at 15:39
  • @BenjaminW. Thanks again. mattficle answered and showed the concrete way to symlink /usr/local/bin. I will follow the way you and mattficle suggested. – Hironobu Nagaya Aug 6 '20 at 16:01

Homebrew doesn't directly install packages to the normal locations in /usr/local/, it installs to its own directory (/usr/local/Cellar by default) and then symlinks the files to /usr/local/bin (or lib, opt, and so on).

You could follow this pattern and create your own directory in usr/local/ to store your executables, and then symlink them to /usr/local/bin. This would let you keep all your own files organized in one place without needing to add a new directory to your $PATH.

  • @mattficle That's a smart idea. I love it! I worried about I could not separate easily my executables from another executables after mixing those. The way you suggested is solved my worry completely. Thank you very much! – Hironobu Nagaya Aug 6 '20 at 15:52