76

How can I update Clam Antivirus via the terminal?

I already have installed clamav, but I want to know how can I update the virus database.

Jjed
  • 13,874
Hippie
  • 761
  • 3
    AFAIK, there is no need to use this command in Ubuntu, the clam virus database is automatically updated. If you execute it you'll get an error such as ERROR: /var/log/clamav/freshclam.log is locked by another process – Savvas Radevic Oct 08 '13 at 22:24
  • 7
    To force the daily update to happen on-demand, you can stop the service & update & then restart it: $ service clamav-freshclam stop and then: $ sudo freshclam and again, $ service clamav-freshclam start – michael Dec 16 '15 at 07:01
  • @michael's comment should be the answer... – Chaim Eliyah Apr 28 '21 at 18:40

5 Answers5

72

To update the ClamAV database do sudo freshclam.

NAME
       freshclam - update virus databases

SYNOPSIS
       freshclam [options]

DESCRIPTION
       freshclam is a virus database update tool for ClamAV.

For offline update, you can also directly download virus definition from database: main, daily and then put them into /var/lib/clamav (remove old files).

Pandya
  • 35,771
  • 44
  • 128
  • 188
turbo
  • 4,622
  • 1
    Will this work for Zorin OS7 Ultimate users? Thanks –  Apr 11 '14 at 15:33
  • mine was up to date, I think it has become automatic now? – Aquarius Power Mar 21 '17 at 03:24
  • ERROR: Can't open /var/log/clamav/freshclam.log in append mode (check permissions!). ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log). – Aaron Franke Dec 14 '17 at 04:27
  • 1
    @AaronFranke, this has solved the problem. https://askubuntu.com/a/909276/118354 For me, it was due to GUI of ClamAv was open. sudo lsof /var/log/clamav/freshclam.log said that. I killed the process using sudo pkill -15 -x freshclam . Problem solved. – Satya Prakash Jul 30 '18 at 07:13
20

Run sudo apt-get install clamav.

Once ClamAv is installed you can set up a script for right click virus scanning in Nautilus.

To update the virus database, open a terminal and enter the following command:

sudo freshclam

To automate this update you can set up a cron job. I'll show how to update the virus database every day at 8:57 AM. First, open the terminal and su to root.

sudo su

Now you need to modify the crontab for the root user.

crontab -e

This opens the root crontab file in the nano text editor. Add the following line

57 08 * * * freshclam

to the crontab and then hit Ctrl+X to exit. Answer yes when prompted to save the file.

  • 3
    If you put it in the root crontab, you don't need sudo. – Pabi Nov 06 '14 at 08:53
  • 4
    Presently, the clamav-freshclam service takes care of updating the definitions (as of 15.04 for sure, possibly as early as 12.04). For Nautilus integration, install clamtk-nautilus (and restart nautilus) – michael Dec 16 '15 at 07:08
  • 2
    @michael I agree, see user846226's answer. It seems that there is a process /usr/bin/freshclam -d --foreground=true is running that updates once an hour. Running freshclam even returns an error because the freshclam's logfile is locked. – zonksoft Apr 19 '20 at 12:28
  • 1
    @zonksoft Indeed with the latest versions of ClamAV and Freshclam under Debian/Ubuntu the process automatically updates the database periodically. No need to do anything manual anymore. – Melroy van den Berg Apr 02 '23 at 20:40
12

The right way to go is to edit freshclam.conf and add the number of dayly Checks you want

vim /etc/clamav/freshclam.conf
Checks 24
##Notify clamd to reload it self
NotifyClamd /etc/clamav/clamd.conf
peris
  • 221
  • 2
  • 3
  • Wow! I was not aware that it would check once per hour by default! It seems like a lot to me... – Alexis Wilke Jan 28 '16 at 07:28
  • @AlexisWilke It should be noted that it doesn't -- that line is commented out in the config file, but can be enabled if you wish – Numeri Sep 09 '18 at 02:37
  • @Numeri A fresh install and I see the Checks 24 parameter by default on Ubuntu 16.04... – Alexis Wilke Sep 09 '18 at 15:25
  • @AlexisWilke I guess that's what I get for assuming the package on Ubuntu would be the same as Manjaro. (Did a fresh install yesterday on Manjaro 17.1.) I agree, 24/day is a little over the top – Numeri Sep 09 '18 at 22:55
4

How to update clamtk (all steps) / clamav (steps 1-3)

NOTE: Read each line before you willy nilly start typing things in Terminal to understand what you are doing to the system.

  1. Remove potentially bad AV installations:

    sudo apt-get remove clamav clamtk freshclam
    sudo apt-get autoremove
    
  2. Reinstall AV

    sudo apt-get install clamav -y      # *(Terminal Version)*
    sudo apt-get install clamtk -y      # *(GUI version)*
    
  3. Update AV Database

    sudo freshclam                    # *(takes ~30 minutes to download definitions)*
    
  4. Configure AV & Scan: This example uses only clamtk

    clamtk                           # (Opens GUI)*
    

    toggle all options beneath settings tab "Network"

    1. toggle "proxy" and type http://127.0.0.1
    2. toggle / reselect "No Proxy" (to gray out #1 above)

    "Update Assistant"

    1. toggle "manual" update option and click apply and "back"
    2. toggle "automatic" update option and click apply and "back". You should now see updated definition count

    "Scan a Directory"

    1. toggle desired directory you want scanned. For system scan, I toggled the entire system (not just /root or /usr).
    2. Click scan and a progress box will appear.

Final Note: typing the phrase clamav --help gives some hints. -y is the same thing as saying yes to installing all dependencies for package. If -y causes issues then exclude and manually press y key when prompted.

This is what I had to do to get clam working, perhaps a glitch for both clamtk and clamav (problem with both). Hope this helps someone else!

muru
  • 197,895
  • 55
  • 485
  • 740
1

in China, the great firewall blocks, so can use only the download files. you can try setting the sever to cn in the freshclam.conf file, but the update will take days. direct download works to get the definitions.

rob grune
  • 1,068