The history of coconuts is deeply connected with the history of people travelling.
Archaeological and genetic findings identify two differentiated populations of coconuts brought under cultivation in two separate locations, one in the Pacific basin and another in the Indian Ocean basin. In the Pacific, coconuts likely were first cultivated on islands in Southeast Asia i.e. Philippines, Malaysia, Indonesia. In the Indian Ocean, the likely center of cultivation was the southern periphery of India, including Sri Lanka, the Maldives and the Laccadives.
The Indian Ocean coconut was transported to the New World by Europeans much later. The Portuguese carried coconuts from the Indian Ocean to the West Coast of Africa, and the plantations established there were a source of material that made it into the Caribbean and also to coastal Brazil. At the same time, the Spanish brought coconuts to the Pacific coast of Mexico from the Philippines, which was for a time governed on behalf of the King of Spain from Mexico. This is why you find Pacific type coconuts on the Pacific coast of Central America and Indian type coconuts on the Atlantic coast.
One exception to the general Pacific/Indian Ocean split is the western Indian Ocean, specifically Madagascar and the Comoros Islands. Here, coconuts are a genetic mixture of the Indian Ocean and the Pacific type. Pacific coconuts were likely introduced to the Indian Ocean by ancient Austronesians establishing trade routes connecting Southeast Asia to Madagascar and coastal east Africa. In fact, present-day inhabitants of the Madagascar highlands are descendants of the ancient Austronesians.