How to Install and Use ClamAV on Ubuntu 24.04 Using Terminal

ClamAV is a popular open-source antivirus software designed for Unix-based systems, including Ubuntu. It provides robust protection against malware, viruses, and other threats. In this guide, we’ll walk you through the process of installing and using ClamAV on Ubuntu 24.04 using the terminal.

Step 1: Update Your Package Lists

Before installing any software, it’s essential to update your package lists to ensure you get the latest version of ClamAV. Open your terminal and run the following command:

sudo apt update

This command fetches the latest information on available packages and updates your local repository.

Step 2: Install ClamAV

With your package lists updated, you can now install ClamAV. Enter the following command in your terminal:

sudo apt install clamav clamtk
  • clamav: This is the core antivirus engine.
  • clamtk: This is a graphical user interface for ClamAV, which is optional but can be helpful for those who prefer a GUI.

Step 3: Update ClamAV Virus Definitions

After the installation, you need to update ClamAV’s virus definitions to ensure it can detect the latest threats. Run the following command:

sudo freshclam

This command will download the latest virus definitions from the ClamAV servers. It’s crucial to keep these definitions updated regularly.

Step 4: Scan Your System

Now that ClamAV is installed and updated, you can begin scanning your system for viruses. To perform a scan, use the following command:

clamscan -r /path/to/directory
  • Replace /path/to/directory with the directory you want to scan. To scan your entire system, use / instead.

For example, to scan your home directory, you would run:

clamscan -r ~

The -r option tells ClamAV to scan recursively through the specified directory.

Step 5: Review Scan Results

Once the scan is complete, ClamAV will provide a summary of the results, including any infected files. If any threats are detected, you can remove or quarantine them based on your preferences.

Step 6: Automate Scans with Cron Jobs

To keep your system secure, you might want to set up automatic scans using cron jobs. This way, you can schedule regular scans without manual intervention. Here’s how to set it up:

  1. Open the crontab configuration file:
   crontab -e
  1. Add a line to schedule the scan. For example, to run a scan every day at 2 AM, add the following line:
   0 2 * * * /usr/bin/clamscan -r /path/to/directory >> /var/log/clamav/scan.log

This command will log the output to scan.log in the /var/log/clamav/ directory.

  1. Save and exit the editor. The cron job will now run automatically based on the schedule you set.

Step 7: Using ClamTk (Optional)

If you installed ClamTk, you can launch it by running:

clamtk

ClamTk provides a user-friendly interface for scanning files and managing quarantined items. You can easily navigate through its options without needing to remember terminal commands.

Conclusion

ClamAV is an effective tool for keeping your Ubuntu system secure from viruses and malware. By following the steps outlined in this guide, you can install ClamAV, update its virus definitions, and scan your system for potential threats—all using the terminal. Regular scanning and keeping your definitions up to date will help ensure that your system remains safe from malicious software.