I was looking through a list of foodstuffs and noticed that nuts have far more energy content, fat content and protein content than cereals (relative to their mass). They don't seem to be especially perishable and humans have eaten them forever- but virtually all agricultural civilizations are built on cereal grains (with an honorable mention for starchy root vegetables like yams). Why is this so when there are so many options for foodstuff in the world that one type would become so dominant?
Let's look at the walnut, since it's been cultivated for a long time.
If you start with the seed, it will take you 10 years (roughly) to have a tree mature enough to produce fruit, assuming you plant it in an area of rich, deep soil, lots of sun, and long summers. For optimum production, you want not many more than 173 trees per hectare, with each tree producing between 30 and 160 kilos of nuts per year (walnut trees often alternate between productive and less productive years). That gives you between 5,190 and 27,680 kilos per hectare per year. Say on average 16,000 kilos per year.
Barley will get you about 7,000 kilos per year.
Sounds like an easy win for the nuts, right? Well, here's the thing. Barley, like most of the cereals, has a short growing season. It is more drought-resistant, tolerates a greater range of climates and soils than walnut trees, requires less water and, obviously, can produce the first crops in a few months after planting in a a brand-new field. And there's a useful byproduct after threshing: the straw. You can use it to make bricks, to feed animals, as fuel, to make baskets and other containers, as padding and insulation, a whole bunch of uses. You can't do that with the walnut trees, even though the wood is a highly useful commodity, if you want walnuts next year.
Overabundance of walnuts? Well, you're kind of stuck with the trees. No one needs barley? Plant rye. And in some cases, you can get two different harvests out of the same patch of ground in one year, sowing winter grain in the fall that will be ready to harvest in the spring, then plant a new crop to harvest in the fall, doubling your food output.
When you start taking all those things into account, suddenly the walnuts aren't looking like a sure win.
As Keith points out, versatility and yield are a major factor.
So is storage. Grains can be stored for months longer than root vegetables and still be edible (potatoes and such go off much quicker, nuts when dried out over time are less tasty too). They're also usually easier to turn into flour and thus bread or pasta, making them more versatile as ingredients for your food as well (not vital maybe, but variety is the spice of life they say).
And then there's the little factor of warfare. It's far easier after a battle ravaged the land to get your grain production going again than to replant orchards and wait for the trees to grow back. Not an unimportant factor at all. In fact it's so important that one of the worst war crimes (or crimes in general) in ancient Greece was cutting down someone else's olive trees. Only the worst criminals and barbarians would stoop so low, and death was the automatic punishment. Burning down a field of grain was an inconvenience for the owner, cutting down his orchards amounted to a slow death by starvation.
Two main considerations:
Even without knowledge of evolution or plant breeding, it is natural for agricultural people to replant the best, most vigorous, tastiest, most productive seeds from last years harvest. Annual crops are therefore subject to much more rapid breeding work than perennials. Even in one lifetime, you can perform 20 selections of barley, but only a few selections of walnut (if you are lucky). The maximum genetic potential of both crops may be similar, but the barley will win the race (and hence win in terms of cultural significance).
Many nut bearing tree species have evolved a strategy of "alternate bearing". A black walnut may only have a "good year" once every three or four years. They often synchronize with other local trees: all of the trees have a "good year" at the same time. Having low production for several years controls the number of seed predators (such as squirrels). Then when the masting year comes, there are too many nuts for the low level of seed predators to take them all. This helps to ensure that some of the nuts will survive. This is still an issue in commercial pecan and walnut cultivation, although there are more tricks and breeding work being done to overcome this.
Chestnut is fairly unique in that it is naturally quite productive. It evolved a strategy of putting out bumper crops each year of more perishable nuts (kind of a boom/bust cycle on a much shorter timescale). Since chestnuts cannot sustain a population of seed predators (they cannot be stored long without molding), they just need to produce an overabundance. For this reason, they are an annually productive crop without much human breeding work necessary (the squirrels did this breeding work long before we got on the scene). This overcomes both difficulties listed above with walnut.
In fact, there have been many cultures which have used chestnuts as a caloric staple. While the squirrel cannot preserve them for storage, we can do so by deliberately drying them.
I'll say the same as others, with different emphasis.
Nuts (and olives) are extremely capital intensive and very difficult to scale. If you plant a nut or olive tree, you need to figure out how to eat for the next decade, because it won't produce fruit till then.
If you plant cereal grains, you'll eat this year. You might forage for half the year, but that's much more realistic than waiting 10 years.
For most of history, food was scarce, and the majority of the population was living at a subsistence level much of the time. (Aristocrats might have been able to eat nuts, but part of the point of aristocracy is conspicuous consumption).
Combine that with the extreme vulnerability to war/hazard, and nuts are a risky proposition.
Another reason for grains to win over nuts.
Overall usage and fit in the puzzle. Most of people think there are nuts or grains to be used, actually, we are trying to reinvent the wheel from scratch - the least-waste economy was the reason grains won the race.
After the harvest the people were left with:
Grains went either to food production (flour, beer/whiskey, groat,...) or to feed domestic animals. Stems were used as either construction material (stem-mud bricks), insulation, mattress filling, ground coverage for domestic animals and bran was used to feed the animals or to make food as well. Then stem-muck mixture was spread over stover and ploughed so the fertiliser would go down in the soil.
There was little-to-no waste from grains cycle.
Nuts, on the other hand provide just nuts and shells.
Another reason is the ease of plantation/harvest. The grains could have been just put in the ground and let grow. Harvest was quite simple as well - mow the field with scythes, collect, beat, sieve and mill. It was quite easy to upscale the production. With nuts, the harvesting process is harder to automate and upscale.
James C. Scott argues in Against the Grain that one key consideration in adoption of grains was actually taxation.
The story goes thus:
people lived off hunting, fishing, horticulture, gathering (including non-domesticated ancestors of our cereal crops) and small scale agriculture
In good climate, this allows actually quite high population denisities in some areas (notably the Tigris/Euphrates area), due to lots of game present
Scott assumes that most groups where not pure farmers or pastoralists or hunter-gatheres, but knew of and practiced several subsistence strategies - as a hedge against bad years and because certain strategies work better at different time of the year - for example huntig during migration season of some animals. If one looks closely at "hunter gatherer" societies in historical times, this pattern is not so rare.
The moment the first proto states arise, the picture changes somewhat. Cereals (compared to root crops, wild plants, hunting ...) are ideal from the perspective of the tax collector: They are easily surveyed, meaning the tax collector can decide that a field of such-and-such a size should yield so-and-so much grains to be taxed, the farmers are fixed in one place, the grains can be stored in the palace and doled out to pay soldiers and civil servants.