Possible Duplicate:
What are PATH and other environment variables, and how can I set or use them?

export PATH="/Users/your_user/scala/bin:$PATH"

I know I need to do this to set up certain applications but I don't understand what exactly it does.

How does it get apps to work?

  • @Becks feisty you are. – Phil Feb 27 '12 at 13:58

Most of the time when you run a program through a graphic user interface, you double-click on an icon which is associated with the program file.

However, there are cases when you need to (or prefer to) run a program by typing its name into a command shell (the Terminal on Mac OS X). When you do so, the shell looks for a program file with that name, and if it finds one, runs it. The PATH is a variable that tells the shell where to look.

On Unix systems, typically all program files, no matter what software package they originate from, are placed in a single directory, /usr/bin. (This is not strictly true, as there is also /usr/local/bin, etc. but that's not important now.) And the PATH is initially set to /usr/bin, so that when you want to run a program, no matter what directory you are in, if you type fooprogram, the shell will immediately look for it in /usr/bin, and if it finds it, run it. Without this capability, the shell would be limited to looking in the current directory (which means you'd always have to be in the program directory to run anything), or else every directory in the file system (which would take a long time).

It is possible to add multiple directories (separated by the : character) to the PATH variable so that it searches all of them in sequence. This is what your command

export PATH="/Users/your_user/scala/bin:$PATH"


You've just installed a software package, which includes some program files, in /Users/your_user/scala. Following the convention, the program files are in the bin subdirectory. So in order to allow you to run those programs directly from the command shell, you need to add /Users/your_user/scala/bin so that the shell looks in there as well. The $PATH stands for the existing value of PATH, so that if PATH was originally /usr/bin, it is now /Users/your_user/scala/bin:/usr/bin. The order matters, so that if both /Users/your_user/scala/bin and /usr/bin contain a program file named scala_prog, it will run the first one.

export is a command which makes this new value of PATH available any time you run a command shell after that.

It's possible that you, the user, won't actually run the scala program files from a command shell, but the scala package itself may need to do so from its own shell scripts. In such a case the shell script will try to run the program with just the program name, and will thus need to have the PATH set properly, just like you would if typing it at the command shell prompt.

| improve this answer | |
  • Thank you Mr. Richter. This must be one of the best answers on this web-site. Thank you very much. One more question, if you please. Do I need to execute this command within the folder from which I want to create this rule? Do I need to go into that folder specifically? Also, do you happen to know where all these rules are stored (export'ed rules) on OSX Lion? I checked bash_profile, .bashrc but they all came as empty files. Thank you. – Phil Feb 27 '12 at 13:57
  • The export command can be executed from any directory, as the value of PATH and other environment variables are stored within the shell's memory space. Also for this reason, the command should be placed in a startup file like .bashrc which the shell reads every time it starts up. In your case, since the program is installed in your home directory, create a new ~/.bashrc and place the command in it. – Paul Richter Feb 28 '12 at 0:47

This is a Unix command to set the order of search for command execution. If you type in the name of a command that's under /Users/your_user/scala/bin, it will be executed. If you didn't have that, you'd need to give the full path name of the command to run it.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.