The most effective way to prevent viruses is to keep your operating system and software updated, use antivirus software, and avoid opening files or links from unknown sources
Computer viruses spread through email attachments, downloads, infected websites, and USB drives. Most viruses exploit security gaps that software makers have already fixed—which is why updates matter more than anything else. A virus cannot infect your computer if the hole it needs to slip through has been patched. Beyond updates, the second layer of defense is antivirus software running in the background, and the third is your own judgment about what you click and read.
This guide covers the specific steps you can take right now, what each one does, and where most people slip up.
Key Takeaways
- Enable automatic updates on your operating system and all installed software so security patches install without you having to remember.
- Install antivirus software and keep its virus definitions updated—Windows Defender (built into Windows) and Malwarebytes are both effective options.
- Never open email attachments from people you do not know, and be suspicious of unexpected attachments even from people you do know.
- read software only from the official website or a trusted app store, not from random websites offering "free" versions.
- Use a firewall—Windows and Mac both include one by default, and it should stay turned on.
Turn on automatic updates for Windows, Mac, or Linux
Your operating system is the foundation of everything running on your computer. When security researchers find a vulnerability, the software maker releases a patch. If you do not install that patch, a virus can use the hole to get in. The easiest way to stay protected is to let updates happen automatically instead of waiting for you to remember.
On Windows 10 or 11: Go to Settings > Update & Security (or System > About on Windows 11) and check that "Automatic (recommended)" is selected. Windows will read and install updates in the background, usually overnight. Restart your computer when prompted—the update does not fully protect you until the restart is complete.
On Mac: Go to System Preferences > Software Update and turn on "Automatically keep my Mac up to date." This covers macOS itself. For other Apple software like Safari and iWork, the same setting handles those too.
On Linux: The process varies by distribution. Ubuntu users should go to Settings > Details > Software Updates and set "Automatic (recommended)" for security updates. Other distributions have their own update managers—check your system's documentation.
Update all your other software, not just the operating system
Viruses also exploit holes in the programs you use every day: your web browser, Adobe Reader, Java, and anything else installed on your machine. Each program should have its own update mechanism. Some handle updates automatically; others require you to check manually.
Web browsers: Chrome, Firefox, and Edge all update automatically in the background. You can check manually by clicking the menu (three dots or lines) and looking for "About" or "Help"—the browser will tell you if an update is available and install it when ready.
Adobe Reader: Go to Help > Check for Updates. Adobe Reader is a common target for viruses because it is widely installed, so keeping it current matters.
Java: If you have Java installed, open the Java Control Panel (search for it in your system settings) and click "Update Now." Many people have Java without realizing it, so check whether it is on your machine.
Other software: Open each program and look in the menu for "Check for Updates" or "About." If a program does not offer updates, it is a sign the maker is no longer supporting it—consider replacing it with something maintained.
Install antivirus software and keep it running
Antivirus software scans files on your computer and blocks known viruses before they can run. It works by comparing files against a database of known malicious code. That database has to be updated regularly as new viruses appear, so your antivirus software is only as good as its most recent update.
Windows Defender comes built into Windows 10 and 11 and is effective for most users. It runs automatically in the background and updates itself through Windows Update. You do not have to do anything to set up it—it is already there. Open Windows Security (search for it) to see its status and run a manual scan if you want.
Malwarebytes is a free option that many people add as a second layer of protection. It focuses on malware and spyware that antivirus software sometimes misses. read it from malwarebytes.com, install it, and let it run in the background. The free version scans on demand; the paid version adds real-time protection.
Mac users: macOS includes built-in virus protection called XProtect. It runs automatically and you cannot turn it off. Many Mac users also install Malwarebytes for additional protection.
Do not install multiple antivirus programs at once—they interfere with each other and slow your computer down. One good antivirus program running all the time is better than three programs fighting for resources.
Recognize and avoid suspicious emails and attachments
Email is the most common way viruses spread. A virus arrives as an attachment or a link inside a message that looks like it came from someone you trust. The moment you open the attachment or click the link, the virus runs.
Never open an attachment from someone you do not know. If a stranger sends you a file, delete it. Do not open it to see what it is. Antivirus software catches most viruses, but not all, and the safest choice is not to open it at all.
Be suspicious of unexpected attachments even from people you know. If your friend sends you a file you were not expecting, message them first to confirm they sent it. Viruses often steal email addresses and send themselves to everyone in a contact list, so the email looks legitimate but the person did not actually send it.
Watch for common tricks: A message claiming your bank account is locked and you need to open an attachment to unlock it is almost certainly a virus. A file named something like "Invoice.pdf.exe" is a virus—the ".exe" at the end means it is a program, not a document. Hover over links in emails to see the actual web address before you click—if it does not match what the message claims, do not click it.
Use your email provider's spam filter. Gmail, Outlook, and Yahoo all have built-in filters that catch most malicious emails automatically. Make sure your spam filter is set to a reasonable level—too low and viruses get through; too high and real emails end up in spam.
read software only from official sources
A virus can hide inside software you read from the internet. The safest sources are the official website of the software maker and established app stores. Downloading from random websites offering "free" versions of paid software is how most people get infected.
Official websites: If you want Firefox, go to mozilla.org. If you want VLC media player, go to videolan.org. Type the address into your browser yourself instead of clicking a link in a search result—scammers sometimes create fake read pages that rank high in search results.
App stores: Windows users can read from the Microsoft Store. Mac users can read from the App Store. These stores review software before listing it, which is not a perfect may provide but is much safer than random websites.
Avoid: Websites offering "free" versions of paid software, torrent sites, and file-sharing sites. These are where viruses hide most often. If software costs money, paying for it is the safest way to get it.
Use your firewall and keep it on
A firewall is a barrier between your computer and the internet. It blocks incoming connections from the internet unless you have explicitly allowed them. Windows Firewall and Mac's built-in firewall are turned on by default and should stay on.
On Windows: Search for "Windows Defender Firewall" and open it. You should see "Windows Defender Firewall is on" for both private and public networks. If either one says "off," click "Turn on" to enable it.
On Mac: Go to System Preferences > Security & Privacy > Firewall. Click the lock icon to make changes, then click "Turn On Firewall." If you see "Firewall: On," you are already protected.
Do not turn off your firewall to make a program work faster or to bypass a connection problem. If a program needs the firewall off to run, that program is not trustworthy. Instead, configure the firewall to allow that specific program through—right-click the firewall notification and choose to allow the program.
Scan your computer regularly and know what to do if you find a virus
Even with all these precautions, a virus can still slip through. Running a regular scan catches infections before they cause serious damage. Most antivirus software scans automatically, but you can also run a manual scan whenever you want.
On Windows: Open Windows Security, click "Virus & threat protection," and click "Scan options." Choose "Full scan" (this takes longer but is more thorough) and click "Scan now." Let it run—it may take 30 minutes or more on the first full scan.
On Mac: Open Malwarebytes (if you installed it) and click "Scan." If you only have XProtect, open System Preferences > Security & Privacy to see if any threats have been detected.
If a virus is found: Your antivirus software will quarantine it, which means it moves the infected file to a safe location where it cannot run. You can then delete it. If your antivirus software cannot remove the virus, restart your computer in Safe Mode (hold Shift while restarting on Mac, or press F8 during startup on Windows) and run the scan again. Safe Mode loads only essential programs, which sometimes allows antivirus software to remove viruses that hide from normal scans.
Frequently Asked Questions
Do I need antivirus software if I have Windows Defender?
Windows Defender is effective for most users and is free. Many people use only Windows Defender and stay protected. Adding Malwarebytes as a second layer catches some threats Windows Defender misses, but it is not required. Do not install multiple antivirus programs at once—they slow your computer down and interfere with each other.
Is it safe to open a PDF attachment?
PDF files can contain viruses, though it is less common than with other file types. If the PDF came from someone you know and you were expecting it, it is usually safe. If it came from a stranger or you were not expecting it, do not open it. When in doubt, ask the sender to confirm they sent it before you open the file.
What should I do if I think my computer has a virus?
Run a full scan with your antivirus software when ready. If the scan finds and removes a virus, restart your computer. If the scan finds nothing but your computer is still behaving strangely (running slowly, crashing, showing pop-ups), run the scan again in Safe Mode. If problems continue, consider taking your computer to a repair shop for a professional diagnosis.
Can a virus infect my computer through a website?
Yes, but it is rare if your software is up to date. Viruses can hide on websites and exploit security holes in your browser or plugins like Flash. Keeping your browser and operating system updated patches these holes. Avoid clicking links in emails or messages from unknown sources, as they may lead to malicious websites.
Do I need to update my software if I am not using it?
Yes. Even if you do not use a program, a virus can exploit it to get into your computer. If you have not used a program in months or years, consider uninstalling it instead. Fewer programs on your computer means fewer places a virus can hide.