It is likely that you already have it installed:
The locate program searches a database for all pathnames which match the
specified pattern. The database is recomputed periodically (usually
weekly or daily), and contains the pathnames of all files which are pub-
The locate program may fail to list some files that are present, or may
list files that have been removed from the system. This is because
locate only reports files that are present in the database, which is typ-
ically only regenerated once a week by the
/System/Library/LaunchDaemons/com.apple.locate.plist job. Use find(1) to
locate files that are of a more transitory nature.
--excerpt from man locate.
On a system like:
OS, ker|rel, machine: Apple/BSD, Darwin 17.3.0, x86_64
Distribution : macOS 10.13.2 (17C88), High Sierra
bash GNU bash 3.2.57
locate - ( /usr/bin/locate, 2017-10-25 )
Note that locate reports matches to the entire pathname, so you may get far more output than you were expecting. I usually pipe the output into less or grep.
$ locate a.out
For a longer list, this would need to be trimmed, viewed with a pager, etc.
Best wishes ... cheers, drl