Skip to content
Home » How to Add to PATH on macOS

How to Add to PATH on macOS

Adding a directory to your PATH is how you get macOS to find a command by name instead of typing its full location every time. There’s more than one way to do it, and which one you want depends on whether you need it for a single session, for your account permanently, or for every user on the Mac. This walks through each method, most common first, and how to confirm the change stuck. zsh has been the default shell on macOS since Catalina (10.15), so these use zsh files — checked on macOS 26.5.2 (build 25F84).

Check your current PATH

Before changing anything, see what’s already there. PATH is one long string of directories separated by colons, so print it one per line to make it readable:

echo $PATH | tr ':' '\n'

The shell searches these directories in order, top to bottom, and runs the first matching command it finds. That order matters later: a directory near the bottom is effectively ignored if the same command also exists higher up.

Add a directory for the current session

To add a directory just for the window you’re in, export a new PATH that includes it. This is the quickest method, and it’s gone the moment you close the window — handy for trying something out:

export PATH="$PATH:$HOME/bin"

Writing $PATH first and your directory after it appends to the end, so existing commands keep priority. Flip the order to "$HOME/bin:$PATH" if you want your directory searched first — for example, to make a newer tool take precedence over a built-in one of the same name. Nothing here is saved yet; a new window starts clean.

Add a directory permanently

For a change that survives new windows and reboots, put the same export line in a zsh startup file. On macOS that file should be ~/.zprofile:

echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zprofile
source ~/.zprofile

>> appends the line and creates the file if it doesn’t exist, and source applies it to the current window right away; new windows read it on their own. You’ll see many guides reach for ~/.zshrc instead. It usually works, but ~/.zshrc is only read by interactive shells, so a PATH set there is invisible to scripts and to apps that shell out. The other common pick, ~/.zshenv, has a subtler issue covered in troubleshooting below. ~/.zprofile avoids both, which is why Homebrew writes its own PATH line there.

Add a directory for every user

To add a directory for every account on the Mac, macOS has a native mechanism that doesn’t touch any shell file. Put a file in /etc/paths.d/ containing the directory, and macOS adds it to everyone’s PATH at login:

sudo sh -c 'echo /opt/mytool/bin > /etc/paths.d/mytool'

Open a new Terminal window for it to take effect. This is how installers like Homebrew and Wireshark register their directories. It needs sudo because /etc is system-owned, so save it for tools that genuinely belong to the whole machine — personal directories still belong in ~/.zprofile.

Confirm the change worked

Open a new window and print PATH again — your directory should be in the list:

echo $PATH | tr ':' '\n'

To check that a specific command resolves to the copy you meant, ask for every match in PATH order. The first line is the one that runs:

$ which -a python3
/opt/homebrew/bin/python3
/usr/bin/python3

Two lines mean two copies exist and PATH order picks the winner. If the one you want is second, its directory is too far down the list — a placement problem, not a missing entry.

Fix the most common problems

When a PATH change doesn’t take, it’s usually one of these:

  • Nothing changed in the open window. Run source ~/.zprofile or open a new one — edits don’t reach shells that were already running.
  • It works in Terminal but not in scripts or apps. The line is in ~/.zshrc; move it to ~/.zprofile, which non-interactive shells also read.
  • Your tool loses to a system command of the same name. The line is probably in ~/.zshenv, which runs before macOS’s /etc/zprofile re-sorts PATH — move it to ~/.zprofile and prepend with "dir:$PATH".
  • The directory is listed but the command still isn’t found. Confirm the file is actually in that directory and is executable: ls -l /your/dir, then chmod +x if needed.

That third one surprises people, so it’s worth seeing directly. macOS runs path_helper from /etc/zprofile at login; it rebuilds PATH with the system directories first and appends whatever came before it. Prepend a directory in an early file and it gets moved to the back:

$ export PATH="/opt/homebrew/bin:/usr/bin:/bin"   # your directory is first
$ eval "$(/usr/libexec/path_helper -s)"           # what login runs
$ echo $PATH | tr ':' '\n'
/usr/bin
/bin
...                        # system entries, machine-specific
/opt/homebrew/bin          # was first — now last

That’s the whole reason ~/.zprofile is the file to use: it loads after path_helper has run, so your directory keeps the position you gave it. If you’re on an older macOS and something here differs, man path_helper and man zshall (under “STARTUP/SHUTDOWN FILES”) are the references to check against your version.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *