The ancient Romans ate a paste called moretum, which was made by crushing cheese, garlic and herbs together. Sounds like Pesto to me!
Basil, the main ingredient of modern pesto, likely originated in India and was first domesticated there. Basil took the firmest root in the regions of Liguria, Italy and Provence, France. The Ligurians around Genoa took the dish and adapted it, using a combination of basil, crushed garlic, grated hard cheese (a mix of Parmigiano-Reggiano and pecorino or just one of the two), and pine nuts with a little olive oil to form pesto.
The first mention of recipe for pesto as it is known today, is from the book La Cuciniera Genovese written in 1863 by Giovanni Battista Ratto. In French Provence, the dish evolved into the modern pistou, a combination of basil, parsley, crushed garlic, and grated cheese (optional). Pine nuts are not included.