MacOS – Mac OS X 10.6 executable not found without full path

bashmacospath

I just installed Apache via MacPorts. It seems that my Mac was absolutely confused about which version of the Apache executables to run.

After moving the Apache executables that ship with the Mac to a directory that is not listed in the PATH variable, trying to run the httpd built by MacPorts fails even though the correct directory (/opt/local/apache2/bin) is listed in the PATH variable.

If I navigate to the directory /opt/local/apache2/bin and type the command httpd I still get the error message

-bash: httpd: command not found

If I type the command with the full path /opt/local/apache2/bin/httpd it works fine.

I've run the command alias to see if something was clashing but the only thing listed is:

alias wget='curl -O'

How do I find what is intercepting the command and preventing the executable being found in the directory, even when I'm inside the same directory?

By the way, the httpd file is executable:

-rwxr-xr-x  1 root      admin  442496  9 May  2012 httpd

Best Answer

Simple. The current directory never belongs to the PATH. For this reason, even if you're inside /opt/local/apache2/bin, you cannot simply type httpd because Bash will only look in your PATH.

So, therefore you would have to type ./httpd here.

To get Bash to look for executables in the MacPorts Apache directory, add the following to your ~/.bash_profile:

export PATH=/opt/local/apache2/bin:$PATH

This will also result in binaries from that directory taking precedence over any other binaries with the same name that might come later in the PATH—check this with which -a httpd.

Related Question