I'm probably repeating much that has already been said--I just quickly skimmed the replies--but there were many ways.
Supermarkets are relatively new, but don't let that lead you to believe that food markets are new. The supermarket is in essence just an amalgamation of the more focused food marketing avenues: greengrocer (fruits and vegetables), butcher (meat), baker (bread and flour), general store (dry goods), etc.
I don't know of any books that deal with food distribution generally, but if you read old texts on specific food production there will be sections on marketing.
For starters, the subsistence farm was the rule rather than the exception. For those entering "commercial" farming (if we want to call it that), access to markets was a major consideration. When your only or primary transportation is via train, you're probably not going to get into a business endeavor that requires you to ship by train if you don't live near enough to a station.
The countryside was quite different. Many more small general stores, more grist mills, more communities generally. Farmers who raised a crop of, say, wheat would take that crop to their local mill. The miller would take a percentage of the crop as payment for the milling, and local folks could then go to the mill to purchase their flour. Thus the farmer's grain crop entered "the market."
Laying hens were kept in moderate numbers, as were milk cows. It seems fluid milk consumption was uncommon enough, but there was a time when the farm wife (typically) could make butter and take it, along with surplus eggs, to the nearby general store. I believe this was often bartered for other goods, though surely cash payment was given as well. In either case, those things were now in "the market." Plenty of communities had local creameries, too, where the farmers could sell their milk and/or cream.
Poultry was typically, it seems, killed and (mostly) plucked, then packed in barrels with ice to be shipped to distributors, who marketed the birds to butchers and such. On a smaller scale, a handful of birds might be offered to the local general store as well.
"Cattle drives" aren't some quaint Western notion; that was how beef made it from the farm/ranch to the larger population centers.