How to install and use clamav on Ubuntu 22.04

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install clamav on Ubuntu 22.04.

clamav is an antivirus that can you can use to scan and detect viruses on your Linux machine.

clamav can be easily installed on any Linux distro, and in Ubuntu 22.04 you can download and install clamav from the official repositories on Ubuntu, by simply using your terminal.

Installing clamav is pretty simple, and it doesn't require any manual setup.

Step 1 - Update

Before installing clamav on your Ubuntu 22.04 machine, make sure that you update your system, and upgrade packages that needs to be upgraded. This way you avoid any possible issue that can happen when package index is not updated.

First you need to check for updates, by running the command below.

sudo apt update -y

Next, if there are packages that must be upgraded, then proceed to do by running the following.

sudo apt upgrade -y

Step 2 - Install clamav

clamav package clamav is the package that contains clamav, and it is available on the security repository of Ubuntu 22.04 "Jammy".

To install clamav, simply run the following.

sudo apt install clamav

clamav needs also the daemon package so clamav runs in the background. To install clamav daemon, you can do so by running the following command.

sudo apt install clamav-daemon

Step 3 - Verify clamav installation

Clamav should be now installed on your Ubuntu 22.04 machine, . However, before doing that, you need to verify that clamav is able to run.

To perform a quick test, to see if clamav is able to run, you can do so by checking clamav version.

clamscan --version

Step 4 - Use clamav

After verifying that clamav was installed correctly, you should be able to use clamav now and scan your machine.

First thing that you need to do is update clamav database, to make sure that the database that contains virus signatures is updated and has the latest signatures, which improves the detection rate.

To update clamav database, run the command below.

sudo freshclam

If you get the error

ERROR: var/log/clamav/freshclan.log is locked by anather process
ERROR: roblen with internal-logger (UpdatelogFile = /var/log/clamav/freshclam.l
9).٠
ERROR: nltlallze: libfreshclam init falled.
ERROR: Intlalization error!

It happens because freshclam service was running in background when you ran sudo freshclam command.

To solve this error, you need to stop freshclam service, and restart it manually.

Stop freshclam

sudo systemctl stop clamav-freshclam.service

Restart freshclam

sudo freshclam

Database is now updated.

Once database is updated, you can proceed to use clamav and scan directories or files on your machine.

The syntax to scan with clamav is

clamscan option path_to_scan/file_to_scan

For example to scan the home directory, run the following.

clamscan -r /home

To scan a file, run

clamscan -r file

Conclusion

In this tutorial, you learned how to install and use clamav on Ubuntu 22.04. In this tutorial, we installed the official package of clamav clamav from the official ubuntu repositories.