Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this directory /foo/bar/. Inside, I have a python file named I made it executable by adding (at the top):

#!/usr/bin/env python

Then, I made it executable by issuing

chmod +x

I edited my path by issuing

sudo nano /etc/paths

I added /foo/bar/ to it.

The problem is that although I can run by typing ./ while I am inside /foo/bar/, it doesn't work from any other location. What am I doing wrong?

Thank you.

share|improve this question
up vote 1 down vote accepted

You need to add /foo/bar to your $PATH environment variable. Navigate to your home directory by typing cd at the prompt, then type nano .profile. Inside this file, add the following line:

export PATH=$PATH:/foo/bar

then save and quit. Exit (or whichever term program you're using) and restart it. /foo/bar should now be in your search path, to make sure type echo $PATH and see if it's at the end. You should now be able to run from anywhere.

share|improve this answer
It is at the end of my $PATH (it already was but I tried adding what you proposed to .profile as well). When I type "" anywhere, it tells me "command not found". – ilovebigmacs Jun 18 '13 at 14:10
First, make sure everything is spelled correctly - /usr/loacl/bin has gotten me before :). I assume you're using bash as your shell, right? Type source ~/.profile (to make sure it's being read), then type hash to refresh the shell's memory of the search path. – MattDMo Jun 18 '13 at 18:44
When I type source ~/.profile, all I see is a blank line. So I guess it is not being read as when editing it, I see the export PATH=$PATH:/foo/bar line in it. What should I do? – ilovebigmacs Jun 20 '13 at 14:06
You won't see anything when typing source ~/.profile. What the source command coes is read the file and execute what's contained within it. After you run the source command and run hash, are you able to run – MattDMo Jun 20 '13 at 14:08
Yes! It works finally. Thank you! I'll accept your answer as the correct one even though the solution is in comments. – ilovebigmacs Jun 20 '13 at 17:50

At your terminal type:

which python

make sure that this path in the shebang at in the 1st line of your .py file. On my system it is


then 1st try:

export PATH=$PATH:/path/to/where/your/script/is

in any terminal

check that the PATH actually stuck by checking:


should have path to your script in there now.

you should now be able to launch you script form anywhere.

the PATH will reset once you close terminal though so you should get pay do get it added permanently to your PATH.

good solution is to have the following bit of code in you .bash_profile:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc

see writeup e.g. this will ensure that .bashrc is loaded every time the terminal is launched as well as when you launch a subshell. Put the export

export PATH=$PATH:/path/to/where/your/script/is

line somewhere in your .bashrc file. quit and restart terminal. That should sort everything out

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.