Changing your PATH macosx

por | 15 diciembre, 2007

Every time you execute a command by using only the command’s name (for example, ls or pwd), your shell looks for the command in a list of directories. That list is stored in the PATH environment variable. The PATH list provides a shortcut for finding commands.

If it weren’t for the PATH list, you would have to type /bin/ls instead of ls, and /usr/bin /vi instead of vi. The command-line utilities supplied with the Mac OS X Developer Tools are located in /Developer/Tools (some of those utilities, such as CpMac and MvMac, are described in Chapter 2, «Using the Command Line»). The /Developer/Tools directory is not normally in your PATH, so if you use any of the commands in /Developer/Tools, you need to type their full pathnames, unless you add the directory /Developer/Tools to your PATH. Here’s how to do that.

Adding a directory to your PATH in tcsh:

  1. Start by editing your ~/.tcshrc file. (Review Chapter 5, «Using Files and Directories,» about editing files from the command line.) If you are using vi, the command is vi ~/.tcshrc
  2. Add a line that says
    set path = ( $path /Developer/Tools )

    This may seem a little odd. After all, you are trying to set the PATH environment variable, not path. What’s going on? Well, tcsh uses an unusual method to set the PATH variable.

    Tcsh requires that you set the shell variable path, and then tcsh sets the actual PATH environment variable. As discussed earlier, shell variables are variables created in your shell that are available only in the shell you are currently using. They are not passed on to child processes as environment variables are.

    Also notice how the command line includes the existing $path value in the new definition, thus adding the new directory to the list. Without $path in the command line, the result would be to replace the old PATH with the single new directory—not at all what you want.

  3. Save your file (the command will depend on which editor you’re using).
  4. Quit the editor (this command will also depend on which editor you’re using). The change will take effect in the next shell you start.
  5. Open a new Terminal window to test the change.
  6. echo $PATHYou’ll see the new directory at the end of the list.
  7. Test using one of the developer tools without typing its full path—for example,
    GetFileInfo "/Applications (Mac OS  

    Figure 7.7 shows the output from the GetFileInfo command.

    Figure 7.7Figure 7.7 Using the GetFileInfo command once it is in your PATH.

    If you are using the bash shell or the sh shell, then you add a directory to your PATH by directly setting the PATH environment variable. Putting this setting in your ~/.profile ensures that it takes effect each time you start a new shell.

Adding a directory to your PATH in bash or sh:

  1. Edit your ~/.profile file.If you are using the vi editor, the command is
    vi ~/.profile
  2. Add a line to the file that says
    export PATH="$PATH:/Developer/Tools"

    Notice how the new value includes the current value of $PATH, then a colon (no spaces!), and then the new directory.

  3. Save the file.
  4. Quit the editor.The change takes effect immediately.
  5. You can check it with
    echo $PATH