
The first is a neat little command in that it shows three uses or interpretations of the period in a single line. Assuming you are in your home directory (if not, running ‘cd’ without any options will take you there), run these commands: One last note, to test the change you made, you can use the echo command, but you need to make the shell reload the. If you don’t need a directory in your path, you can reverse the process by deleting the unwanted directory still taking care to preserve the no spaces, colon separation rules.

Putting less frequently used or really massive directories later in the path may give you a little performance boost (although these days things are pretty fast, so you have to be a little anal to really enjoy this). You have the ability to optimize the searches your shell will do on your behalf each time you run a command by organizing your PATH logically. Note that in the third example the new directory is added to the end of the PATH. For example, to add the directory /mightyq/bin to the PATH shown above, the line could become any of the following examples:Įxport PATH=/mightyq/bin:/opt/local/bin:/opt/local/sbin:$PATHĮxport PATH=/opt/local/bin:/mightyq/bin:/opt/local/sbin:$PATHĮxport PATH=/opt/local/bin:/opt/local/sbin:$PATH:/mightyq/bin profile being careful to separate it from other directories there with colons and careful not to introduce unwanted spaces (everything after the space will be ignored). So, to add a new directory to the path, simply add it to the existing PATH line in. By default, this will add ‘:/bin:/sbin:/usr/bin:/usr/sbin’ to the end of the PATH for you which is useful because most everything you run from the command line lives there. The $PATH at the end of the example above tacks the previous value of the variable (if it exists) onto the end of the PATH. If the PATH variable was not exported, when you run a shell script, the PATH would no longer exist and it is possible that the script would fail. You may think to yourself that you don’t plan to make any subsequent shells, but this happens whenever you run a shell script. Defining a variable without exporting it makes it available only to the current shell, not to any subsequent shells. The export= keyword in front of that line has a very specific purpose.

If there are spaces in the directory name you want to add, you’ll need to escape the space by preceeding it with a \backslash or by putting the path in quotes (export PATH=”/path/here”). In particular, there cannot be spaces around the equals sign or between any of the directories. The use of spaces in this command, or their lack, matters. There are a few things to note before making changes. Sometimes the PATH variable can get lengthy, but chances are yours just has a few directories separated by colons, perhaps something like this:Įxport PATH=/opt/local/bin:/opt/local/sbin:$PATH In your editor, find the line that starts with export PATH= and give it a look to make sure it doesn’t already contain the directory path you’re going to add. While this is handy because you can make any available command run whenever you drop to a shell, we’re concerned with changing an environment variable, PATH. profile is read when you open a Terminal window and each line is executed just like typing a command into the Terminal window.

If not, then you can use TextEdit to edit your.

If you are comfortable using the vi editor, you probably don’t need to read any further. Following these directions will allow you to add a directory to the search PATH. For convenience, adding directories to this environment variable means you don’t have to go hunting for a file each time you run it. When you run a command from a UNIX or UNIX-like shell, the shell looks for the executable file using the directories listed in your PATH variable as a map.
