Because the Romans were an agrarian society, the phases of the moon and the seasons were the first yardsticks they used to build a calendar. The earliest known example supposedly dates from the founding of Rome (753 B.C.). That early calendar had ten months:
Martius (31 days), Aprilis (30 days), Maius (31 days), Junius (30 days), Quintilis (31 days), Sextilis (30 days), September (30 days), October (31 days), November (30 days), December (30 days)
Notice that December (Deci=10) is the tenth month, and there are only 304 days in this calendar. The other 61 days were not in a named month. Martius 1st (the first day of the year) was on the Vernal Equinox, which was the first day of planting for farmers.
In the 713 B.C, the calendar was reformed and two months were added at the end of the year.
Martius (31 days), Aprilis (29 days), Maius (31 days), Junius (29 days), Quintilis (31 days), Sextilis (29 days), September (29 days), October (31 days), November (29 days), December (29 days), Ianuarius (29 days), Februarius (28 days)
This calendar had 360 days, but was still mismatched with the solar year of 365 days, four hours, and fifty six minutes, so an accommodation was made to add a leap month. February was shortened to twenty-four days, to produce a twenty-seven day leap month about every three years. This leap month was called the Mensis Intercalaris.
The system described above lasted some 650 years until the dictatorship of Julius Caesar. Caesar made January 1st the beginning of the year and set the days of the months to their current length. December, the original tenth month, was now the twelfth month. A day was added at the end of February every four years to account for the four hour difference between the calendar and solar year. Caesar also changed Quintilis to July to honor himself. Not to be outdone, his successor, Caesar Augustus, named August after himself.
What is the origin of the names of the months? March was named for Mars, the God of War; April from Aphrodite, Goddess of Love. May comes from Maia the mother of Mercury; June from the God Juno. January comes from the God Janus and February from Februa, the Roman festival of Purification.
Oddly, September was renamed Germanicus during the year 37 A.D. April. May, and June were renamed Neroeus, Claudius, and Germanicus during the year 65 A.D.