PDA

View Full Version : How to find and edit the PATH file




V6Pony
Jun 17, 2012, 09:05 AM
I'm trying to edit my path from a terminal in Lion. I can use export to get a temp result. I would like to edit the file so the path stays. What is the file name where is it located? I thought it was in .bash_profile or .bashrc. But I can't find these files on my system. :o

Thanks



kryten2
Jun 17, 2012, 09:33 AM
Try .profile. If the files don't exist, create them like :

echo 'export PATH=/path/to/some/dir:$PATH' >> .profile

Login Scripts
Mac OS X provides support for login scripts and environment property lists to allow you to set environment variables and aliases that are automatically set whenever you run a new shell. There are three ways to do this:

Bourne shell (bash, zsh, and so on):
To persistently set environment variables and add aliases, you can add the appropriate alias, variable assignment, and export commands to the following files:

~/.profile—executed automatically for all login shells.
~/.bash_profile—similar to .profile, but only runs for bash login shells.
~/.bashrc and ~/.zshrc—executed automatically for all non-login bash or zsh shells (when you explicitly type bash or zsh on the command line or run a script that starts with #!/bin/bash or #!/bin/zsh).
You may also find it useful to create a .bashrc file that sources your .profile file. For example:
. $HOME/.profile
Sourcing is described in more detail in “Subroutines, Scoping, and Sourcing.”
C shell (csh, tcsh, and so on):
To persistently set environment variables and add aliases, you can add the appropriate alias, set, and setenv commands to the following files:

~/.login—automatically executes for all login shells.
~/.cshrc—automatically executes for all non-login shells (when you explicitly type bash on the command line or run a script that starts with #!/bin/csh or #!/bin/tcsh).
You may also find it useful to create a .cshrc file that sources your .login file. For example:
source $HOME/.login
Sourcing is described in more detail in “Subroutines, Scoping, and Sourcing.”
All login shells:
To persistently set environment variables, add them to the ~/.MacOSX/environment.plist property list file. For more information, see Runtime Configuration Guidelines.

V6Pony
Jun 17, 2012, 10:15 AM
Try .profile. If the files don't exist, create them like :

echo "export PATH=/path/to/some/dir:$PATH" >> .profile

Thanks for you answer kryten2. I'm new at this. I used the find ~/.profile it did not exist. I used the export PATH=/Users/dleathers:$PATH >> .profile . This created the .profile file in my ~. But the path statement is not in the file. Are you saying that I just enter the PATH " as I want it to be" in the .profile with a text editor? Then when I login the path will be read from this file?

kryten2
Jun 17, 2012, 10:38 AM
Perhaps you forgot the echo at the front? Now the file exists you can just put in export PATH=/Users/dleathers:$PATH. Note : files with a dot at the front eg .profile are hidden files. If you want to open them with TextEdit do in Terminal :

open -a TextEdit .profile

or

open -e .profile

Then when I login the path will be read from this file?
Try and you'll see. Check your path with echo $PATH

Better use single quotes so we don't get variable expansion eg

echo 'export PATH=/path/to/some/dir:$PATH' >> .profile