Locate tool won’t work, how do I fix I was trying to update the locate database, but when input sudo /usr/libexec/locate.updatedb, I got a bunch of errors. When I try to use locate again it would not work. I can’t remember what I did, but I ended up finding out that the locate.updatedb file had been corrupted. I got locate to work again by using Time Machine to recover the locate.database file. But I want to be able to update locate without corrupting the file. How do I fix this?
The command to update the database is

sudo /usr/libexec/locate.updatedb


It should get run automatically every week from /System/Library/LaunchDaemons/com.apple.locate.plist but you can run it manually if required.