set $PATH environment variable?

tr333

Registered
how do i set/change the PATH environment variable?

i have tried editing /etc/profile but nothing changes.
i can get it to work by typing PATH="mypath" at a bash prompt in X11, but when i start a new xterm the PATH has reverted to the original.
 

barhar

Registered
The following was performed with 'Tiger', MacOS X 10.4.0, running.

For those using 'Terminal':

To add a directory path, or directory paths, to PATH (and thus creating '~/.bash_profile'):

01. Launch 'Terminal'.
02. Enter ...

echo 'export PATH=xyz:$PATH' >> ~/.bash_profile

(and press the <return> key) ... where 'xyz' is your desired path(s).

03. Open another 'Terminal' window.
04. Enter ...

env

<return> ... and note that 'PATH' now includes 'xyz'.

-----

To remove the '.bash_profile' file (thus, returning PATH to its default value):

01. Launch 'Terminal'.
02. Enter ...

cd ~/; ls -la; rm -rf .bash_profile; ls -la

<return> ... and note the '.bash_profile' file, in the first 'ls -la' no longer exists in the second 'ls -la'.

03. Open another 'Terminal' window.
04. Enter ...

env

<return> ... and note that 'PATH' has returned to its initial paths.

---- ----- ----- ----- ----- -----

For those using 'X11':

01. Enter ...

cd /etc; sudo cp bashrc bashrc_; open /etc

02. Drag 'bashrc' to the 'Desktop', and double click on (the 'Desktop' copy of) 'bashrc'.
03. Enter (at the end of the file, on a new line) ...

export path=xyz:$PATH

[
03 October 2005, 23.17
Correction:

As per lurk's observation:

path and PATH are two different variables. PATH as a env varialble, and path as a user defined variable. Thus, ...

export path=xyz:$PATH

... is incorrect. In 'X11' the correct 'bashrc' line would be ...

PATH=$PATH:xyz

Thanks lurk
]

... where 'xyz' is your desired path(s).

04. Close and save the file.
05. Click on (the 'Desktop' copy of) 'bashrc' and select the 'Finder' 'File, Get Info' menu item.
06. Naviagate down to hte 'Ownership & Permissions:' section, clicking on the disclosure triangle.
07. Click on the pad lock, change 'Owner:' to 'system' - do not worry if it snaps back to the current user, and change 'Group:' to 'wheel'.
08. Drag the 'Desktop' based 'bashrc' file onto the 'etc' window - clicking on 'Authenticate', 'Replace', and (entering any needed info, and then) 'OK' of the three windows that follow.
09. Open another 'X11' window.
10. Enter ...

env

<return> ... and note that 'PATH' now includes 'xyz'.

-----

Hey, what about that 'bashrc_' file in '/etc'?.
It is a backup of your original 'bashrc' file. Should you want to restore your PATH settings - all you need to do is enter

cd /etc; sudo mv bashrc_ bashrc

<return>.
 

barhar

Registered
In bash 'export' sets an environment variable ('path' in this case) to a value. In ...

export path=xyz:$PATH

... 'path' and '$PATH' are really the same variable; thus 'path=xyz:$PATH' appends the original 'path' value after the 'xyz' path(s) you supply.
The 'export' command tells the Mac's UNIX core to accept the new concatenated string 'xyz:eek:riginal_PATH_entry' as the new environment 'path' value.

[
03 October 2005, 23.17
Correction:

As per lurk's observation:

path and PATH are two different variables. PATH as a env varialble, and path as a user defined variable. Thus, ...

Thus, the above statement (with respect to 'Terminal') is rewritten as ...

"In bash 'export' sets an environment variable ('PATH' in this case) to a value. In ...

export PATH=xyz:$PATH

... 'PATH' and '$PATH' are really the same variable; thus 'PATH=xyz:$PATH' appends the original 'PATH' value after the 'xyz' PATH(s) you supply.
The 'export' command tells the Mac's UNIX core to accept the new concatenated string 'xyz:eek:riginal_PATH_entry' as the new environment 'PATH' value."

With respect to 'X11's 'bashrc' you only need ...

PATH=$PATH:xyz

Thanks lurk
]
 

lurk

Mitä?
barhar said:
I... 'path' and '$PATH' are really the same variable; thus 'path=xyz:$PATH' appends the original 'path' value after the 'xyz' path(s) you supply.
That should not be working in bash because variable names are case sensitive. You should be using PATH and $PATH for this to be correct because "path" and "PATH" are not the same.
 

barhar

Registered
lurk, you are absolutly correct.

When viewing 'env' in X11, I just did not take notice of the two ...

PATH=...
path=...

... lines.

Indeed, 'path' is a user defined variable; and, 'PATH' is an 'env' variable.

Corrections were made to the two previous 'barhar' posts (above).

A summary:
in 'Terminal' - "echo 'export PATH=xyz:$PATH' >> ~/.bash_profile" works.
In 'X11' - "PATH=$PATH:xyz" works.

Again, thanks for noticing the mistake.

Sincerely yours,
 
Top