Skip to main content

Install ClamAV Antivirus

Updated over a week ago

Introduction

ClamAV is an open-source antivirus engine designed to detect trojans, viruses, malware, and other malicious threats. It's widely used on Linux systems and provides essential protection for servers, email scanning, and system security.

A running instance of Ubuntu 24.04.

However, it is compatible with Ubuntu 22.04 and Debian.

1. Upgrading and upgrading the server's system:

sudo apt update
sudo apt upgrade

2. Install ClamAV and the ClamAV Daemon

sudo apt install clamav clamav-daemon

ClamAV: The antivirus scanner to detect and eliminate malware.

ClamAV Daemon: A service that enables automatic updates and scheduled scans.

3. Verifying the installation

We can do it by checking the installed version of ClamAV:

clamscan --version

Output example:

4. Updating ClamVM database

After installing ClamAV, updating the virus database is essential to ensure your system is protected against the latest threats. Before starting with the update, we have to stop clamav-freshclam:

sudo systemctl stop clamav-freshclam

To download the latest database version:

sudo freshclam

Output example:

Once the database update is completed, restart the clamav-freshclam service, and enable it to run automatically on system boot:

sudo systemctl enable clamav-freshclam --now

To check permissions, ownership, and the last modification dates.

ls -l /var/lib/clamav/

It will also verify that the dates correspond to the most recent updates:

To disable the ClamAV Freshclam Service (optional)

sudo systemctl disable clamav-freshclam --now

It will disable automatic updates.

5. Basic ClamAV Terminal Commands

To scan a specific file:

clamscan /path/to/file

To scan a particular directory:

clamscan -r /path/to/directory

To scan a directory with subdirectories:

clamscan /path/to/file -l /path/to/logfile

Scan and remove infected files:

clamscan /path/to/file --remove

For more commands and help:

clamscan --help

Conclusion

ClamAV is a powerful tool that can help protect your system from viruses and other malware. To keep your system safe, you should keep ClamAV up to date, scan frequently, and scan incoming email.

Did this answer your question?