If you don’t want to worry about updates, dependencies and paths, use Homebrew or MacPorts to install additional utilities. This will be the easiest approach by far.
If the binary is not available in Homebrew/MacPorts, or you want to manage things on your own, read on.
Because macOS comes from a Unix heritage, you may want to store system files in /usr/local/bin
for command line applications and scripts that belong to the system locally and not to a specific user. Recent versions of macOS have the directory installed as part of the OS install, otherwise you can create it first by running:
sudo mkdir -p /usr/local/bin
You can move any command line application to that folder by running:
sudo mv my-binary /usr/local/bin/
/usr/local/bin
already should be listed at the beginning of /etc/paths
, but you can run the following to insert it as the first entry in case it's missing:
grep -w /usr/local/bin /etc/paths || \
sudo sh -c 'echo -e "1i\n/usr/local/bin\n.\nw\nq" | ed /etc/paths'
If the software to be installed comes with a lot of support files, and you want to keep everything bundled together to make upgrades or removal easier, you can also choose to store the whole package in a sub-directory of /opt
(-> /opt/foo-package
). To make its binaries accessible via the shell, you can either
- add the path of the binaries to
/etc/paths.d/foo-package
(i.e., as root, run echo /opt/foo-package/bin >> /etc/paths.d/foo-package
) and restart your shell, or
- symlink all binaries from
/usr/local/bin
(-> cd /usr/local/bin; sudo ln -s /opt/foo-package/bin/* .
). This is basically what Homebrew does as well.
Some users make a second directory for user level scripts, but this is even more subject to personal preference.
mkdir -p ~/.local/bin
In this case, you'll want to have each user's path include this location by modifying the shell startup scripts (~/.bash_profile
for bash, ~/.zshrc
for zsh)
export PATH=~/.local/bin:$PATH