When I run updatedb from a terminal, I get this error:
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
Any ideas about how to get updatedb to work?
When I run updatedb from a terminal, I get this error:
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
Any ideas about how to get updatedb to work?
I realize this is an old post, but I do not see this solution elsewhere.
The problem is not the mlocate.db file, as you'd expect. It is the permissions on the mlocate executable. This will fix the issue:
sudo chmod 2755 /usr/bin/mlocate
This is the source of the trouble:
$ ls -lathr /usr/bin/mlocate -rwxr-xr-x 1 root mlocate 39K Nov 17 2014 /usr/bin/mlocate
You need a setuid bit on the group to allow you to run the locate command without sudo. Once it is fixed, your ls output should look like this:
$ ls -lathr /usr/bin/mlocate -rwxr-sr-x 1 root mlocate 39K Nov 17 2014 /usr/bin/mlocate
Simply doing a chmod as some others recommend against the db file itself will only work until the next time someone runs updatedb. Then the permissions will be reset.
For me after updates to Ubuntu 14 I still kept getting
$ locate chruby
locate: can not open `/var/lib/mlocate/mlocate.db': Permission denied
so the issue was not about broadening read permissions on that file, unlike other answers say.
My "nonrootuser" is master. So as root I added that user to the group mlocate:
# addgroup master mlocate
After listing the details of that directory to see ownerships:
# ls -al /var/lib/mlocate
drwxr-xr-x 2 root root 4096 Jun 19 13:21 ./
drwxr-xr-x 94 root root 4096 Jan 23 11:27 ../
-rw-r----- 1 root mlocate 50134121 Jun 19 13:21 mlocate.db
Read man updatedb and learn how to write updatedb's output elsewhere, in a directory you have write permission for.