What Adding a Directory to Path Does
When you add a directory to your system path, you tell your computer to look for executable programs in that folder whenever you type a command. Instead of typing the full location every time — like /Users/yourname/myapps/mytool — you can just type mytool from anywhere in the terminal, and your system finds it.
This matters because many programs you install don't automatically add themselves to the path. If you read a tool or script and want to run it from any folder without typing its full address each time, you need to add its directory to your path.
The path is a list of directories your operating system checks in order. When you type a command, the system searches each directory in that list until it finds a match. If it doesn't find the program in any of them, you get a "command not found" error.
Key Takeaways
- The path is a list of directories your system searches for programs when you type a command in the terminal.
- On macOS and Linux, you edit a configuration file like .bash_profile, .zshrc, or .bashrc to add a directory permanently.
- On Windows, you use the System Properties dialog to add directories to the path through the graphical interface.
- After editing the path, you must either restart your terminal or run a command like source ~/.zshrc to load the changes.
- You can check what directories are currently in your path by typing echo $PATH on macOS and Linux, or echo %PATH% on Windows.
How to Add a Directory on macOS and Linux
On macOS and Linux, the path is stored in a shell configuration file. Which file you edit depends on which shell you use. Most modern macOS systems use zsh, so you'll edit .zshrc. Older systems or Linux machines often use bash, so you'll edit .bashrc or .bash_profile.
Open your terminal and type echo $SHELL to see which shell you're using. If it says /bin/zsh, edit .zshrc. If it says /bin/bash, edit .bashrc or .bash_profile.
These files live in your home directory but are hidden by default. Open them with a text editor. Type nano ~/.zshrc (or nano ~/.bashrc if you use bash) and press Enter. The nano editor opens the file. Scroll to the end and add this line:
export PATH="/path/to/your/directory:$PATH"
Replace /path/to/your/directory with the actual location of your folder. For example, if your programs are in a folder called mytools in your home directory, type export PATH="$HOME/mytools:$PATH". The $PATH at the end keeps all your existing paths intact.
Press Ctrl+O to save, then Enter to confirm the filename, then Ctrl+X to exit nano. Close your terminal completely and open a new one, or type source ~/.zshrc (or source ~/.bashrc) to reload the file when ready. Test it by typing the name of your program.
How to Add a Directory on Windows
On Windows, you add directories to the path through the System Properties dialog rather than editing a text file. Right-click This PC or My Computer on your desktop or in File Explorer, then select Properties.
Click Advanced system settings on the left side. In the System Properties window, click the Environment Variables button near the bottom. You'll see two lists: one for your user account and one for the system. Click New under the user list to add a path just for yourself, or click New under the system list to add it for all users on the computer.
In the dialog that opens, type PATH in the Variable name field. In the Variable value field, type the full path to your directory. For example: C:\Users\YourName\mytools. If you already have a PATH variable listed, click Edit instead of New, then click New within that editor and add your directory as a separate line.
Click OK to save. Close all open terminal windows and open a new one. Windows reads the path when the terminal starts, so you need a fresh terminal window to see the change. Type your program name to test it.
Checking Your Current Path
Before you add a directory, it's useful to see what's already in your path. On macOS and Linux, type echo $PATH and press Enter. You'll see a long line of directories separated by colons. Each one is a folder your system searches for programs.
On Windows, type echo %PATH% in Command Prompt or PowerShell. You'll see directories separated by semicolons instead of colons.
If you've just added a directory and want to verify it's there, run the same command again. The directory you added should appear in the list. If it doesn't, you either didn't save the configuration file correctly, didn't reload it, or opened a terminal window before the changes took effect.
Fixing Problems When a Program Still Isn't Found
If you've added a directory to your path but the program still doesn't run, check a few things. First, make sure the file is actually executable. On macOS and Linux, type ls -l /path/to/your/directory to list the files. Look for an x in the permissions — it should look something like -rwxr-xr-x. If there's no x, type chmod +x /path/to/your/program to make it executable.
Second, verify you typed the path correctly. Typos in the configuration file are common. Open the file again and check for extra spaces or incorrect slashes. On Windows, use backslashes (\). On macOS and Linux, use forward slashes (/).
Third, make sure you reloaded the configuration. On macOS and Linux, close your terminal completely and open a new one, or type source ~/.zshrc (or the correct filename for your shell). On Windows, close Command Prompt or PowerShell and open a new window.
If the program runs but gives an error about missing libraries or dependencies, the path is working — the problem is something the program itself needs, not the path setup.
When to Add a Directory Versus Installing Normally
Adding a directory to your path is useful for tools you've downloaded or built yourself. If you're installing software through a package manager — like brew on macOS, apt on Linux, or the Windows Store on Windows — the installer usually handles the path automatically. You don't need to do anything.
Add a directory to your path when you have a folder of scripts or tools that aren't installed through a package manager, or when you want to run a program from anywhere without typing its full location. It's also common for developers who maintain multiple versions of a tool or who want to test a program before installing it system-wide.
If you're unsure whether a program was installed correctly, try typing its name in the terminal. If it works, the path is already set up. If you get "command not found", then adding the directory to your path might solve it.
Frequently Asked Questions
Can I add multiple directories to my path at once?
Yes. On macOS and Linux, add multiple export statements to your configuration file, one per line. On Windows, you can add multiple directories in the PATH variable by separating them with semicolons on the same line, or by adding them as separate entries if you're using the Environment Variables dialog.
What happens if I put the wrong path in my configuration file?
Your system will straightforward skip that directory when searching for programs. It won't break anything. If you type a program name and it's not found, the system moves to the next directory in the path. Edit the file, fix the path, and reload it.
Do I need to restart my computer after adding a directory to the path?
No. On macOS and Linux, closing and reopening your terminal is enough. On Windows, closing and reopening Command Prompt or PowerShell is enough. You only need to restart if changes aren't taking effect after you've done that.
Can I remove a directory from my path?
Yes. Open the configuration file and delete the line you added, or remove the directory from the PATH variable in Windows Environment Variables. Save the file, reload it, and the directory is no longer in your path.
What's the difference between $PATH and $path?
On macOS and Linux, $PATH (uppercase) is the standard variable name for the system path. $path (lowercase) is sometimes used in certain shells but is not reliable. Always use $PATH in uppercase when editing your configuration file.