In the 4th Century there was a strong monastic tradition, which usually involved living in solitude or small groups in the wilderness. By the 12th Century the monastic life was being lived in large groups, and generally close to large communities. How did one tradition evolve into the other?
Monasticism was unknown until the end of the third century. Paul expressed that he preferred celibacy, but there was no "command from the Lord" to remain unmarried. (Simon) Peter, according to Catholic tradition the first Pope, was himself married.
Widows were treated with special respect, but encouraged to remarry and bear children if still within child bearing age. More emphasis was placed on missionary and charity work than meditation or spiritual development.
Over time, the custom developed of going into the desert (or otherwise being alone), when faced with an important life decision, a desire to commune with God, etc. These people were called hermits, a term which means "desert dwellers". The most famous of these early hermits was Anthony of Egypt (251-356). Athanasius' Life of St. Anthony began to make the hermit life popular, both because it portrayed it as a path to eternal life, and because Anthony was portrayed as an athlete for Christ, a heroic figure.
Now there were so many hermits that it was starting to get crowded. A hermit named Pachomius (290-346) instituted some rules; that the monks should live in isolated huts, produce their own food and clothing, and should never speak to one another. Because they were no longer dependent on public charity, their growth was unlimited, and monasteries and monks began to spread rapidly.
St. Pachomius the Great is one of the figures instrumental in moving monastic life from the life of hermits (old as dust) and small communities.
As for cenobitism, the widows in the New Testament were parochial nuns. If you consider the function of old widows in almost every church, you will find they generally fulfill the duties that nuns do, though in a local setting. A large church would have a fair number of these celibate (since post-reproductive age), prayerful and godly women. If you consider how Paul treats 'the widows' it is precisely as an order of nuns would be treated by the overseeing abbess or bishop.
The mens' tradition seems to have grown out of the former mens' tradition of hermit life, such as what St. John the Baptist lived. It is with Antony (my own patron) and Pachomius that we see people gathering around a single elder or abbot and forming a community. It is with Pachomius that the communites became sizable; Scetis (Antony's) still exists, but it has never been large. Pachomius' communities did not themselves survive (as many of the pilgrim cities did not) but his tradition and practices which allowed this organization did.
There are basically three forms of monastcism and they are still extant.
Anachoretism - the first form to emerge was living in complete solitude. Hermits however sometimes accepted disciples that would watch their life and then leave. There are still hermits living e.g. in rocky parts of Mt. Athos that don't see other monks for long periods of time.
Idiorythmia - when monasticism became popular, some areas fit for monastic life started attracting monks and monastic societes as e.g. Nitra emerged. Monks would meet at Liturgy and would counsel some things together, yet every brother would be econimically independent.
Cenobitism - as Bob already said - this form was instituted by St Pachomius. Monks live in a commune. They work together and their material needs are fullfilled by the community. This form is the safest and easiest, because monks can comfort each other and the strict obedience protects them from straying on their spiritual path. This is why it is most popular form today. But the two former are not extinct.