How To Install mlocate on Ubuntu 20.04
Introduction
In this tutorial we learn how to install mlocate
on Ubuntu 20.04.
What is mlocate
mlocate is:
mlocate is a new implementation of locate, a tool to find files anywhere in the filesystem based on their name, using a fixed pattern or a regular expression. Unlike other tools like find(1), locate uses a previously created database to perform the search, allowing queries to execute much faster. This database is updated periodically from cron.
Several implementations of locate exist: the original implementation from GNU’s findutils, slocate, and mlocate. The advantages of mlocate are:
it indexes all the filesystem, but results of a search will only include files that the user running locate has access to. It does this by updating the database as root, but making it unreadable for normal users, who can only access it via the locate binary. slocate does this as well, but not the original locate.
instead of re-reading all the contents of all directories each time the database is updated, mlocate keeps timestamp information in its database and can know if the contents of a directory changed without reading them again. This makes updates much faster and less demanding on the hard drive. This feature is only found in mlocate.
Installing mlocate will change the /usr/bin/locate binary to point to mlocate via the alternatives mechanism. After installation, you may wish to run /etc/cron.daily/mlocate by hand to create the database, otherwise mlocate won’t work until that script is run from cron itself (since mlocate does not use the same database file as standard locate). Also, you may wish to remove the “locate” package in order not to have two different database files updated regularly on your system. Task: kubuntu-desktop, kubuntu-full, xubuntu-desktop, ubuntustudio-desktop, ubuntu-budgie-desktop
There are three methods to install mlocate
on Ubuntu 20.04. We can use apt-get
, apt
and aptitude
. In the following sections we will describe each method. You can choose one of them.
Install mlocate Using apt-get
Update apt database with apt-get
using the following command.
sudo apt-get update
After updating apt database, We can install mlocate
using apt-get
by running the following command:
sudo apt-get -y install mlocate
Install mlocate Using apt
Update apt database with apt
using the following command.
sudo apt update
After updating apt database, We can install mlocate
using apt
by running the following command:
sudo apt -y install mlocate
Install mlocate Using aptitude
If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude
using the following command.
sudo aptitude update
After updating apt database, We can install mlocate
using aptitude
by running the following command:
sudo aptitude -y install mlocate
How To Uninstall mlocate on Ubuntu 20.04
To uninstall only the mlocate
package we can use the following command:
sudo apt-get remove mlocate
Uninstall mlocate And Its Dependencies
To uninstall mlocate
and its dependencies that are no longer needed by Ubuntu 20.04, we can use the command below:
sudo apt-get -y autoremove mlocate
Remove mlocate Configurations and Data
To remove mlocate
configuration and data from Ubuntu 20.04 we can use the following command:
sudo apt-get -y purge mlocate
Remove mlocate configuration, data, and all of its dependencies
We can use the following command to remove mlocate
configurations, data and all of its dependencies, we can use the following command:
sudo apt-get -y autoremove --purge mlocate
References
Summary
In this tutorial we learn how to install mlocate
package on Ubuntu 20.04 using different package management tools: apt
, apt-get
and aptitude
.