No, installing ram will not cause a virus infection in your computer.
You're much more likely to have gotten from an attachment to an email, or from a download or from clicking on something at a website.
You can run an antivirus to get rid of it, like the free Microsoft Security Essentials, or Avast. You can also run Malware Bytes malware program. But the only certain way to get rid of a virus infection is to save your data, then format and reinstall the operating system.