Even running as root, would give me that error. I have spent months scouring the web, and they all point to that command being the correct command to create a local database.
joe@delljoe:~> updatedb -U /home/joe/ -l0 -o /home/joe/.locate.db updatedb: can not open a temporary file for `/home/joe/.locate.db'
I just found out apparmor was blocking the executable from reading/writing from anywhere except the system default directory.
So there are three options:
1) Disable it for mlocate completely
sudo aa-disable /usr/bin/locate sudo aa-disable /usr/bin/updatedb sudo mv /etc/apparmor.d/usr.bin.locate /etc/apparmor.d/usr.bin.locate.OLD sudo mv /etc/apparmor.d/usr.bin.updatedb /etc/apparmor.d/usr.bin.updatedb.OLD sudo touch /etc/apparmor.d/usr.bin.locate sudo touch /etc/apparmor.d/usr.bin.updatedb
2) Tune or update /etc/apparmor.d/usr.bin.updatedb and /etc/appmarmor.d/usr.bin.locate to allow writing to certain locations. For example updatedb can write to /home/*/.locate.db etc. This is recommended for production multi-user environments. (I am just using my laptop. And I am lazy)
3) Disable apparmor completely for dev envs