What adding a directory to your path does

When you add a directory to your system path, you tell your terminal to look in that folder for programs you type as commands. Normally, you have to type the full location of a program — something like /Users/james/scripts/backup.sh — every time you want to run it. Once that directory is in your path, you can type just backup.sh from anywhere and the terminal finds it.

Your path is a list of directories separated by colons (on Mac and Linux) or semicolons (on Windows). When you type a command, the terminal searches each directory in order until it finds a match. If it finds nothing, you get a "command not found" error.

Adding a directory to your path is permanent — it stays there until you remove it. The steps differ depending on whether you use Mac, Linux, or Windows, and which shell your terminal runs.

Key Takeaways

  • Your path is a list of directories your terminal searches when you type a command; adding a directory to it lets you run programs by name instead of typing their full location.
  • On Mac and Linux, you edit a shell configuration file like .bashrc, .zshrc, or .bash_profile and add a line that exports the new directory to your path.
  • On Windows, you open System Properties, navigate to Environment Variables, and add your directory to the PATH variable in the list.
  • After editing your path, you must restart your terminal or run a command like source ~/.zshrc to load the changes.
  • You can check your current path by typing echo $PATH (Mac and Linux) or echo %PATH% (Windows) in your terminal.

Adding a directory to your path on Mac and Linux

On Mac and Linux, your path lives in a shell configuration file. Which file depends on your shell. If you use bash, the file is usually .bashrc or .bash_profile in your home directory. If you use zsh (the default on newer Macs), it is .zshrc. If you use fish, it is .config/fish/config.fish.

To find out which shell you use, open your terminal and type echo $SHELL. The output will show the path to your shell — look at the last word after the final slash.

Open your configuration file in a text editor. If you use nano (a simple editor built into most terminals), type nano ~/.zshrc (or ~/.bashrc if you use bash). The tilde (~) is a shortcut for your home directory. At the bottom of the file, add a new line like this:

export PATH="/path/to/your/directory:$PATH"

Replace /path/to/your/directory with the actual path to your directory. If your scripts are in /Users/james/scripts, write export PATH="/Users/james/scripts:$PATH". The $PATH at the end preserves all your existing paths — if you leave it out, you will lose access to system commands.

Save the file. In nano, press Ctrl+O, then Enter, then Ctrl+X. Now reload the configuration file by typing source ~/.zshrc (or the name of whichever file you edited). Your new directory is now in your path.

Adding a directory to your path on Windows

On Windows, the path is stored in an environment variable you can edit through System Properties. Right-click the Start button and select System, or open Settings and search for "environment variables".

Click Environment Variables near the bottom of the System Properties window. Under "User variables for [your username]", look for a variable named PATH. If it exists, click it and then click Edit. If it does not exist, click New, type PATH as the variable name, and leave the value blank for now.

In the Edit Environment Variable window, click New and type the full path to your directory — for example, C:\Users\james\scripts. Click OK three times to close all the windows. Close any open terminal windows and open a new one. Your new directory is now in your path.

Checking your path and troubleshooting

To see all the directories currently in your path, type echo $PATH on Mac or Linux, or echo %PATH% on Windows. The output is a long string of directories separated by colons (Mac and Linux) or semicolons (Windows).

If you added a directory but commands still do not work, check three things. First, make sure you restarted your terminal or ran source on your configuration file — changes do not take effect in an already-open terminal. Second, verify the path you added is correct by opening a file manager and navigating to it. Third, make sure the program file itself has execute permission. On Mac and Linux, type chmod +x /path/to/program to make it executable.

If you added a directory to your path and now system commands are broken, you probably overwrote your existing path instead of adding to it. On Mac and Linux, edit your configuration file again and make sure your line ends with :$PATH. On Windows, check that PATH contains multiple entries separated by semicolons, not just your new directory.

When to add a directory to your path

Add a directory to your path when you have scripts or programs you run often from different locations. Common examples are personal scripts, development tools you built yourself, or third-party programs that do not come with an installer.

Do not add a directory to your path just to run something once. If you only need to run a program one time, type its full path instead. Adding too many directories to your path can slow down your terminal slightly and make it harder to find which program is actually running if two directories contain programs with the same name.

If you install a program through a package manager like brew on Mac or apt on Linux, the installer usually adds the directory to your path for you. You only need to do it manually for programs you write yourself or download without an installer.

Understanding path order and conflicts

Your terminal searches directories in the order they appear in your path. If two directories contain a program with the same name, the one in the directory that appears first in your path runs. This matters if you want to override a system command with your own version.

For example, if you have a custom version of python in /Users/james/bin and you want it to run instead of the system version, add /Users/james/bin to the beginning of your path, not the end. On Mac and Linux, put it before $PATH: export PATH="/Users/james/bin:$PATH". On Windows, drag your new directory to the top of the list in the Environment Variables window.

Most of the time, you want your custom directory at the end of your path so system commands run first and your custom programs act as backups. Only move a directory to the front if you specifically want to override something.

Frequently Asked Questions

What is the difference between PATH and path?

On Mac and Linux, $PATH (uppercase) is the environment variable your terminal reads. When you type export PATH=, you are setting that variable. The word "path" (lowercase) refers to the concept or a file path like /Users/james/scripts. They are the same thing in different contexts.

Can I add multiple directories to my path at once?

Yes. On Mac and Linux, separate them with colons: export PATH="/dir1:/dir2:/dir3:$PATH". On Windows, click New multiple times in the Environment Variables window and add each directory as a separate entry. The order matters — directories listed first are searched first.

How do I remove a directory from my path?

On Mac and Linux, open your configuration file and delete the line you added, or remove just that directory from the export statement. On Windows, open Environment Variables, select PATH, click Edit, find your directory in the list, select it, and click Delete. Save and restart your terminal.

Why does my program still say "command not found" after I added its directory to my path?

The most common reason is that you have not restarted your terminal since making the change. Close your terminal completely and open a new window. If that does not work, check that the path you added is spelled correctly and actually contains the program. On Mac and Linux, also make sure the program file has execute permission by running chmod +x /path/to/program.

Can I use a relative path like ~/scripts in my PATH?

On Mac and Linux, you can use the tilde (~) to mean your home directory, so export PATH="~/scripts:$PATH" works. On Windows, relative paths do not work in the PATH variable — you must use the full path like C:\Users\james\scripts.