4

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?

xiota
  • 5,038

4 Answers4

4

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.

Martin Thornton
  • 5,996
  • 12
  • 32
  • 43
3

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
Marcos
  • 730
2

Please run the command with sudo:

sudo updatedb
chili555
  • 61,330
-1

Read man updatedb and learn how to write updatedb's output elsewhere, in a directory you have write permission for.

waltinator
  • 37,856