Three directions for avoiding temptation, courtesy of John Owen:
1. If you would avoid entering into temptation, labour to know your own heart. Become acquainted with your own spirit, natural temperament, lusts and corruptions, and natural, sinful, or spiritual weaknesses. By finding where your weakness lies, you may be better able to keep at a distance from all occasions of sin.
2. Watch against every kind of occasion, opportunity, activity, society, solitude, or business that tends to entangle your natural temperament, or that provokes your corruption. It may be that there are some situations, some kinds of society or business, in which you have never in your life been able to escape the temptation that arises, because it is so suitable to ensnare or provoke your particular corruption. . . . If you have any love for your soul, it is time for you to awake and deliver yourself, as a bird from an evil snare.
3. Be sure to lay up provisions in store against the approach of any temptation. This is part of our watchfulness over our hearts. . . . As for the provision to be laid up, it is what is provided for us in the gospel. Gospel provisions will do this work; that is, they will keep the heart full of a sense of the love of God in Christ. This is the greatest preservative in the world against the power of temptation.
And a couple of final quotes to underscore this last point:
"Store up in your hearts a sense of the love of God in Christ, the eternal purpose of his grace, the savour of the blood of Christ, and his love in the shedding of it; get a taste for the privileges we have through this: our adoption, justification, acceptance with God; fill your hearts with thoughts of the beauty of holiness, as the effect Christ intended in dying for us; and you will, in the ordinary course of walking with God, have great peace and security from the disturbance caused by temptations."
"The apostle tells us that the peace of God will keep our hearts (Phil. 4:7). . . . What is the peace of God? It is a sense of his love and favour in Jesus Christ. Let this abide in you, and it shall garrison you against all assaults whatever. Besides, there is in this sense of love and favour that which is in direct opposition to all the ways and means that temptation uses to approach our souls. Striving to obtain and keep a sense of the love of God in Christ, by its very nature, undermines all the workings and insinuations of temptation. Therefore, lay up a store of gospel provisions which will make the soul a place of defence against all the assaults of temptation."
(from Chapter 16 of John Owen, Temptation Resisted & Repulsed. Edited and abridged by Richard Rushing. Original edition, 1658. New edition, Edinburgh: Banner of Truth Trust, 2007.)