With changing time in and after the Vedic Period, the Brahmins introduced the system of Ashramas, according to which a person goes through four stages in his life i.e. Bramhacharya, Grihastha, Vanaprastha and Samnyasa.
In Bramhacharya Asharam, man learnt the Vedas and led a simple life. Grihastha Asharam he got married and had a family. In Vanaprastha Asharam, he had to live in forests and meditate while in the last Samnyasa Asharam, he gave up everything and become samnyasin.
Around this time, great thinkers like Mahavira and Buddha were preaching their way of life and to leave home in search of knowledge. Many Jain and Buddha followers left their homes in search of truth and stayed in Sanghas, which are associations of such people. The rules for Sanghas is comprised in the book called Vinaya Pitaka and there were separate branches of sanghas for men and women.
It was mandatory to get permission before joining a sangha; children had to take permission from their parents, a woman had to seek her husband’s permission while the slaves had to take permission of their masters.
People living in sanghas had to lead a very simple life. They meditated, acted as peace-brokers and taught Buddha’s teachings. As these people had to beg for food they were called Bhikkus and Bhikunnis which means beggar in Prakrit.
During rains, Jain and Buddhist monks lived in temporary shelters built by their supporters in gardens or took shelter in caves. With time, they felt the need of permanent shelters and hence the monasteries or Viharas formed.