You can follow various ways to avoid getting malware, including updating your Mac OS in routine, not installing apps from outside App Store, never clicking on links from unknown emails.