Praise be to Allah.
The correct scholarly view is that masturbation is haraam. For more information please see the answer to question no. 329.
With regard to the rulings concerning the daytime in Ramadaan, please see the answer to question no. 38074.
Young men have to fear Allaah their Lord, and keep away from listening to or looking at the things that will provoke their desire. They should make the most of Ramadaan to discipline themselves, for this is the month of the Qur’an and the month of piety. It is not befitting for a Muslim to fail to make the most of this month to forsake forbidden desires and seek reward, fearing his Lord. Allaah says of the fasting person in a hadeeth qudsi: “He forsakes his food, his drink and his desires for My sake.” Narrated by al-Bukhaari, 1894; Muslim, 1151.
Shaykh Ibn ‘Uthaymeen said:
One should be patient in avoiding masturbation, because it is haraam as Allaah says (interpretation of the meaning):
“And those who guard their chastity (i.e. private parts, from illegal sexual acts)
6. Except from their wives or (the slaves) that their right hands possess, for then, they are free from blame;
7. But whoever seeks beyond that, then those are the transgressors”
And the Prophet (peace and blessings of Allaah be upon him) said: “O young men, whoever among you can afford to get married, let him do so, for it is more effective in lowering the gaze and guarding one’s chastity. And whoever cannot afford that should fast.”
If masturbation were permissible, the Prophet (peace and blessings of Allaah be upon him) would have told them to do it, because it is easier and because people find pleasure in it, unlike fasting which is difficult. Because the Prophet (peace and blessings of Allaah be upon him) enjoined fasting instead, this indicates that masturbation is not permissible.
Majmoo’ Fataawa al-Shaykh Ibn ‘Uthaymeen, 19.189.
You should try hard to get married so that you can give up this bad habit. Seek the help of your Lord by praying to Him and obeying Him, so that you can rid yourself of this sinful habit.
We ask Allaah to purify your heart and protect you from sin, and to help you to do that which He loves and which pleases Him.
And Allaah knows best.