Identifying where a package came from I just tried to upgrade nmap with my package manager but got knocked back because it's supposedly not installed. Even though it is:   

brew upgrade nmap  
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
No changes to formulae.
Error: nmap not installed

nmap --version 
Nmap version 6.40-2 ( http://nmap.org )
Platform: x86_64-apple-darwin10.8.0
Compiled with: liblua-5.2.2 openssl-0.9.7l nmap-libpcre-7.6 nmap-libpcap-1.2.1 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: kqueue poll select


brew info nmap
nmap: stable 7.60 (bottled), HEAD
Port scanning utility for large networks
https://nmap.org/
Conflicts with:
  ndiff (because both install ndiff binaries)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nmap.rb
==> Dependencies
Required: openssl ✔
Optional: pygtk ✘
==> Options
--with-pygtk
    Build Zenmap GUI
--HEAD
    Install HEAD version

Is it possible to find how a package, utility, or application came to be present, and/or installed on a macOS host? I recall being able to do something like this in the past, on a Linux (Debian) host, and figured there might be some kind of system or utility in place for macOS.
This will show you your installed brew packages

brew list


There may be options in other package managers, but nmap can also be installed by downloading the disk image and installing manually.