Your computer can get a virus by engaging with an infection vector such as an infected USB drive, email attachment, pirated software, malicious website, etc. A computer can also get a virus through a social engineering attack like a phishing email that deceives you into downloading malware.