Coffee plants grew wild in East Africa. Sometime before 1000 AD, the people who lived in Ethiopia, in East Africa, began to pick the red coffee berries and mash them up. They mixed the berries with fatty meat (like bacon) to make an energy bar like the North American pemmican.
By about 1000 AD, the Ethiopians were selling coffee beans to Islamic traders. Those traders brought the coffee beans back to the Arabian peninsula in the Abbasid Empire to sell there. Slowly more and more people heard about coffee. Traders began selling coffee all over the Abbasid Empire and in India. Farmers grew coffee in the Arabian Peninsula, and did their best to keep anyone else from getting any coffee plants. That way they could charge whatever they wanted for coffee.
By 1453, people in the Ottoman Empire figured out how to roast the beans, grind them, and brew coffee into a drink. Because Muslims were not supposed to drink wine or beer, a lot of people began serving coffee to their guests instead. (Some caliphs said not to drink coffee and tea either, but people mostly drank them anyway.)
In the 1500s, Ottoman traders brought the new fad of coffee-drinking to Italian ports. Europeans loved coffee (which they mixed with another new fad, sugar), but they didn’t want to pay the high prices. It wasn’t hot enough in Europe to grow coffee (or sugar), so Dutch colonists (part of the same Holy Roman Empire as Italy) brought coffee plants to the Caribbean and the Americas. In the Americas they could grow coffee (and sugar) themselves and not have to buy it from Islamic traders. Dutch colonists enslaved West African people to work on huge coffee plantations in South America, where they were treated very badly and many died after only a few years.
Right before the American Revolutionary War, the American rebel colonists didn’t want to drink tea, because the British were taxing tea. So people showed that they were rebels by drinking coffee instead. That’s why even today most Americans drink coffee, while most British people still drink tea.
By 1900, though, as more and more people drank coffee, British colonists encouraged people in Kenya and other British colonies to grow both coffee and tea.