In a previous post on getting NLTK up and running on Mac OS X, I mentioned that once you install a separate version of Python, with which to play and to work, you need to adjust your PATH. Doing so, directs your computer to use the newly-installed version over the version that comes with Mac OS X. This kind of direction, of indicating to the operating system which programs to use, is known as adjusting the PATH.
When you run a command from a UNIX or UNIX-like shell, the shell looks for the executable file using the directories listed in your PATH variable as a map. Your PATH variables are really just a part of your shell profile. Nothing more than one part of a larger list. For the record, my
.bash_profile file looks like this:
% more .bash_profile # Bash Profile # PROMPT PS1='\W % ' PS2='$ ' # MacPorts # export PATH=/opt/local/bin:/opt/local/sbin:$PATH # Emacs alias emacs='/usr/local/Cellar/emacs/23.3b/bin/emacs' # ALIASES alias Learn='cd Dropbox/personal/programming/learn' alias Research='cd Dropbox/research' # Set architecture flags export ARCHFLAGS="-arch x86_64"
I’ve included the
more command that I typed to look at my
.bash_profile, but apart from that this is the entire file. Reading it, you’ll see:
- That I’m goofy enough to name the file: note that this line and everything else that isn’t something I want the shell to act upon is “commented out” with a hash,
#, at the beginning of the line.
- Next I have the customization for how I prefer my prompt to look: here it’s simply the current working directory.
- Next is my obsolete MacPorts variable information. (I should probably get rid of that.)
- Then there’s a list of PATH variables to enable the system to find things I have installed using Homebrew, including Python, as described in my previous post.
- Then there’s a few more variables for apps I use.
- And finally the aliases I use for directories in which I often work and don’t feel like re-navigating the file system.
That’s it. That’s all there is to PATH. If you are using Mac OS X, it’s a good bet that Bash is the default shell and that the file you need to edit is
.bash_profile. The best way to do that, in all honesty, is to use a simple CLI (command line interface) editor like
vi — there’s also
emacs to be sure. Because of the dot at the beginning of its name,
.bash_profile is not normally viewable in the Finder. You can search and find the terminal command that changes that, but, to be honest, there are an awful lot of little hidden files that I just don’t want to have to deal with on a daily basis. When I want to work with hidden files, I can find them through
ls -a (list –all files) and then edit them while in the terminal.