1 Stay away from people who have colds, the flu, or other respiratory tract infections. 2  If you haven't had measles or chickenpox or if you didn't get vaccines against these diseases, avoid people who have them. 3  Wash your hands often. 4  This helps prevent the spread of viruses and bacteria that may cause pneumonia.here are a number of steps you can take to help prevent getting pneumonia. 1  Stop smoking. 2  You're more likely to get pneumonia if you smoke. 3  Avoid people who have infections that sometimes lead to pneumonia.