Use a anti-virus/malware software program.
That’s not the issue. The issue is being connected to the big bad world when it’s not necessary.
I have a separate machine for web and email use, the rest stays behind a “firewall” that consists of non-connectivity. A high-resistance air connection, if you will.