How to install mlocate on CentOS 8 and get your file‑searching back in a snap
CentOS 8 ships without the handy mlocate tool that lets you find files by name instantly. If you’ve ever tried find / -name foo.conf only to stare at hours of output, installing mlocate is the fix. This guide shows you the exact dnf commands, explains why each step matters, and shares a quick tip I learned from a friend who ran into the same issue after an upgrade.
Why install mlocate on CentOS 8?
When you’re hunting for a config file or a log that disappeared during a system tweak, mlocate gives you a quick lookup against a pre‑built database. The database is refreshed once daily by default, so most of the time you’ll get instant results instead of sifting through directory trees.
Step 1: Make sure the AppStream repository is active
CentOS 8’s core packages live in AppStream, but sometimes your system is set up to use only BaseOS. Run:
sudo dnf repolist all | grep appstream
If you see enabled, you’re good. If not, enable it with:
sudo dnf config-manager --set-enabled AppStream
Enabling the repo is crucial; without it, dnf can’t find mlocate.
Step 2: Install mlocate
sudo dnf install mlocate
The install pulls a small package (~70 KB) that contains the command and its database scripts. It’s lightweight compared to bloated “find‑all‑in‑one” GUIs you’ve seen in other distros.
Step 3: Build the initial database
After installation, run:
sudo updatedb
This populates /var/lib/mlocate/mlocate.db. The first build can take a minute on a machine with many files; future searches will be instant. You only need to run this again if you add or remove large directories that should be searchable.
Step 4: Use mlocate
mlocate sshd_config
If you’re looking for multiple patterns:
mlocate -i '*.conf'
The -i flag makes the search case‑insensitive, which is handy when you’re not sure how a filename was capitalized.
A real‑world observation
I once helped a friend who upgraded from CentOS 7 to 8. He ran grep /etc/ssh/sshd_config across /etc and got no hits because the file had moved into /usr/libexec. After installing mlocate, he searched with mlocate sshd_config and found the new location within a second—no more guessing or manual grep loops.
Common pitfalls
- Forgot to run updatedb? You’ll get an empty result set even though the file exists. The database is out of date until you update it.
- Running as root only once? updatedb requires superuser rights because it scans system directories. If you try as a normal user, it will silently skip many paths.
When mlocate isn’t enough
If you need to search by content (not just name), grep -r, ripgrep, or ack are better tools. But for quick file location on CentOS 8, mlocate is the lightweight go‑to solution.