In the manpage of
whereis, it clearly says (emphasis mine):
The whereis utility checks the standard binary directories for the specified programs, printing out the paths of any it finds.
The path searched is the string returned by the sysctl(8) utility for the “user.cs_path” string
Contrary to that,
which is the tool commonly used to check where a binary is for your user’s path.
The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.
That explains your difference, since
/opt/local/bin is not a system-wide “standard” path—after all, MacPorts is a completely optional installation—and
sysctl only has
/usr/bin:/bin:/usr/sbin:/sbin in its
user.cs_path per default.
In general, stick to
which -a to find a binary rather than using
You can theoretically change
sysctl -w user.cs_path=/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
but I don’t know if that is such a good idea.