Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

firstyearprof

macrumors member
Original poster
Apr 16, 2007
52
0
Hi all,

I'm a mac newbie, windoze vet. I'm about to install a little program on my Mac to use through Terminal. I'd like for my Mac to recognize the program without my having to type in the entire path of where it is everytime I want to use it.

In windows (XP) days, I'd do this by placing the path to the program in System Properties -> Environmental Variables -> PATH. That way, in DOS, I could just type the program name and my machine would know where it was. Is there an equivalent for Macs? Or does OSX somehow magically know where programs are? Thanks in advance...
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
Mac OS X does, in fact, have an equivalent. It's the PATH environment variable. Adding stuff to it isn't anywhere near as simple as in Windows, though.

Here's a tiny little shell script that might help:
Code:
`export PATH=$PATH:$1`>>~/.profile

I haven't tested this little thing, but what it's supposed to do is this:
  1. Read the contents of the PATH variable
  2. Append the first argument to the end of it
  3. Append the resulting command to the ~/.profile file
Close and reopen the Terminal for the change to take effect. Note, this script requires BASH as the shell in order to work (BASH is the default shell in Mac OS X 10.4).
 

localoid

macrumors 68020
Feb 20, 2007
2,447
1,739
America's Third World
If bash is your shell you can add the path to ~/.bash_profile.

For example, to add the path /usr/local/bin

In terminal create/edit ~/.bash_profile
Add the following line: PATH=$PATH:/usr/local/bin; export PATH
Save the file
Type: source ~/.bash_profile (to get the shell to read the file without closing/restarting terminal)


Note: ~/.bash_profile sets for current user (only)
 

mkrishnan

Moderator emeritus
Jan 9, 2004
29,776
15
Grand Rapids, MI, USA
Isn't the technically better way to do this to put the executable in the /usr/local directory? I.E. something like this (say abc was the executable):

sudo mv abc /usr/local/abc
sudo chown root:admin /usr/local/abc

The executable will then be available to all users without needing to bother with paths.
 

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
Isn't the technically better way to do this to put the executable in the /usr/local directory? I.E. something like this (say abc was the executable):

sudo mv abc /usr/local/abc
sudo chown root:admin /usr/local/abc

The executable will then be available to all users without needing to bother with paths.
The problem with this is that most command-line programs install themselves by default in /usr/local/bin, which is NOT in the path... Is /usr/local in the default path?
 

localoid

macrumors 68020
Feb 20, 2007
2,447
1,739
America's Third World
Much/most of the open source stuff tends to put (via make install, etc.) the executable in /usr/local/bin and man stuff in /usr/local/man -- much/most of system wide files ends up in /usr/bin...

You can create symlinks, or move files, add $path, etc., but everyone seems to have their way of handling it, which is usually what method works best for that person, etc.
 

-Alan-

macrumors member
Mar 10, 2007
91
0
I'm a Mac newbie too and can see how all of these answers can be confusing. For what I understand, when you use the terminal, the terminal runs within a shell program. OSX's default shell is bash. You can check this by the prompt command:

echo $SHELL

Bash has a profile, .bash_profile, within the root of each user account. In this profile you can add items to your PATH. It is a hidden file so therefore its name is preceded with a "dot." From the prompt, you can list all files--including the hidden files--with this command:

ls -a

If the .bash_profile doesn't exist then you must create one.

In the file, add this line:

export PATH=/path/to/location:$PATH

Edit the /path/to/location then save the file. Restart the terminal and you should be set.

You can check the path with this command:

echo $PATH
 

dukebound85

macrumors Core
Jul 17, 2005
19,131
4,110
5045 feet above sea level
I am trying to install NCO with these instructions. How do I add this path? The above responses weren't making too much sense as I am able to run commands from the ~/usr/local/bin. I do not have a .bash_profile
Use the DMG files if you do not have MacPorts installed. You may need to add /opt/local/bin to your executable path to access the operators.

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.