As for practical ways of getting rid of this habit, I suggest the following:
1)Take all necessary means to control your sexual desire (shahwa), and avoid anything and everything that may lead you to masturbate.
2)Always be around family members and other people; try not being alone unless when necessary. Do not sleep alone in your room, and do not have TV or internet to yourself.
3)Avoid bad company, and endeavor to stay in the company of the pious and righteous, in the Mosque, and with learned Ulama as much as possible.
4)Try and fast as much as possible, and generally eat less especially foods that may stir your sexual desire such as meat and dairy products.
5)Continually ask Allah, especially after the Fard prayers, to free you from this habit.
6)Involve yourself with acts of worship as much as possible, like reciting the Qur'an, Dhikr and Salawat.
7)Consider marriage. The jurists (fuqaha) state that if one is overwhelmed with sexual desire to the extent that they fear committing a sin, marriage becomes obligatory. Speak to your parents and start looking for a suitable spouse with whom you can fulfill your desires in a Halal way.
8)Finally, there is nothing more effective in helping you avoid this sinful habit than exercising your will-power (himma) and fighting against your lower, desiring self (nafs) and your sexual appetite. It may be a good idea to impose a monetary or another form of penalty on yourself every time the sin is committed. Continue the struggle wholeheartedly and you will see the benefits, InshaAllah. For more on this, read the books of Imam al-Ghazali (Allah have mercy on him) in particular hisIhya Ulum al-Din.
View more