Abstinence, the practice of oneself from indulging in something deeply, is the foundation to attain Moksha. This foundation needs to be strong to attain the goal in life. If your mind is agitated by evil thoughts, you cannot reach the summit of Sadhana.
It is the mind which really controls all our actions. When desires arise in mind, we take the step ahead to fulfill that desire. But if this mind is controlled not to follow every desire, it’ll act accordingly. Let’s not allow evil thoughts enter our mind. Empty spaces do form in our mind time to time. Law of nature says on this planet no space remains empty, it’s filled with air. Same applies to our inner mental world too. It is upon us now to fill that space in our mind with good thoughts. If these empty spaces are filled with sublime divine thoughts, the vicious mind is bound to change gradually and thus change us as a person. As you think, you become; this is the immutable psychological law of human being.
To follow this Brahmacharya you need to take sanyasa. Sanyasa in true sense means “Non Attachment”. It is the destruction of all vasanas. You need to free yourself from all Moh and Maya. They are cause of many of our Vasanas. Definitely leaving the worldly ties helps in attaining this state of mind more easily. But when you have responsibilities as a person still left, be it parents, wife, children, taking such a step is not the right way. You don’t need to retire to forest to attain Moksha. You can always be in this world, give up worldliness, and thus be out of this material world. This has been followed by so many of our saints and seers.