One of the hoped-for graces of maturity is self-knowledge and humble self-awareness of weaknesses. Accordingly, there are three basic practices that a person can do to help avoid temptation.
First, make an amendment of life so that you do not put yourself in situations where you know you are likely to be tempted. Such voluntary restrictions require both discipline and freedom.
Second, remove yourself from situations of temptation when they do occur. Such removal can occur physically by leaving a situation, mentally by choosing to change your thought process, and spiritually by turning to prayer and seeking divine guidance and protection.
Third, fill yourself with what is good, true and beautiful so that temptation will be less appealing. Saint Paul encourages this practice in Philippians 4:8. Such actions include surrounding yourself with good and virtuous friends, prayer, studying Scripture, and so forth. When filled with grace, temptation has less appeal.