Not having sex is the only way to prevent HPV. Since HPV is so common, even those who have had one partner can still get the virus.
Using condoms correctly each time you have sex reduces the risk of getting sexually transmitted infections, and might offer some protection against HPV. Keep in mind that skin in the anal and genital area not covered by a condom can still be affected.
If you are 26 or younger, there is an HPV vaccine that can help protect you against the types HPV that most commonly cause problems in men. The HPV vaccine (Gardasil) works by preventing four common HPV types, two that cause most genital warts and two that cause cancers, including anal cancer. It protects against new HPV infections; it does not cure existing HPV infections or diseases (like genital warts). It is most effective when given before a person’s first sexual contact.
CDC recommends the HPV vaccine for all boys ages 11 or 12, and for males through age 21 who have not already received all three doses. The vaccine is also recommended for gay and bisexual men and men with compromised immune systems (including HIV) through age 26, but it is more effective when given at younger ages.