There is no magic bullet to defend against ransomware. There is no such thing as 100% protection. However, if you consider multiple levels of controls, such as training, firewalls, patch management, anti-malware, security policies, and so on., you significantly lower the chances of infection.
Preventative measures are not enough though! You need countermeasures in the case of infection. Backup and disaster recovery solutions, incident response plans, test restores, etc., will enable you to recover in the case of infection.