Go Back   MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 18, 2007, 08:24 AM   #1
firstyearprof
macrumors member
 
Join Date: Apr 2007
OS X equivalent to adding PATH variables in Windows

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...
firstyearprof is offline   0 Reply With Quote
Old Jun 18, 2007, 08:54 AM   #2
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: 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).
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote
Old Jun 18, 2007, 09:03 AM   #3
localoid
macrumors 68020
 
localoid's Avatar
 
Join Date: Feb 2007
Location: 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)

Last edited by localoid; Jun 18, 2007 at 09:18 AM.
localoid is offline   0 Reply With Quote
Old Jun 18, 2007, 09:22 AM   #4
mkrishnan
Moderator emeritus
 
mkrishnan's Avatar
 
Join Date: Jan 2004
Location: 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.
__________________
Mira C. Krishnan
mkrishnan is offline   1 Reply With Quote
Old Jun 18, 2007, 09:32 AM   #5
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
Quote:
Originally Posted by mkrishnan View Post
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?
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote
Old Jun 18, 2007, 09:43 AM   #6
localoid
macrumors 68020
 
localoid's Avatar
 
Join Date: Feb 2007
Location: 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.
localoid is offline   0 Reply With Quote
Old Jun 18, 2007, 10:33 AM   #7
-Alan-
macrumors member
 
Join Date: Mar 2007
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
__________________
Convert
-Alan- is offline   1 Reply With Quote
Old May 25, 2012, 04:22 PM   #8
dukebound85
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 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
Quote:
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
dukebound85 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Xcode gets the wrong path when adding files printz Mac Programming 1 Mar 6, 2014 05:01 AM
OS X Equivalent of Windows dBpoweramp JoelBC Digital Audio 2 Nov 26, 2013 03:42 PM
Windows compatible equivalent for TextExpander 4 features ianbonachita Mac Applications and Mac App Store 1 Mar 3, 2013 07:54 AM
Upgrade Path from SL/XP 32 to ML/Windows 8 Pro 64 Tanda OS X 10.8 Mountain Lion 0 Dec 2, 2012 04:52 PM
Screenflow equivalent for Windows Doctor Q Mac Applications and Mac App Store 4 Sep 5, 2012 03:17 PM

Forum Jump

All times are GMT -5. The time now is 08:54 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC