Regard it as a sin. Realise it brings the wrath of Allaah.
All causes and reason that lead to this sin, terminate these. Stop looking at porn, nudity and anything that encourages you to do this act.
Be regular in Salaat. Avoid thinking of loose things and fantasising about women. Fear Allaah.
Keep the company of the pious. Befriend good company.