What @josie and @Earthbound_Misfit said. Also, people throughout history have shown great ingenuity in making alcoholic drinks out of local ingredients. Some of my buddies made prison wine in a bathtub when we were underaged in college. It was nasty. People are creative and will go to great lengths to get hammered, but in the past the drinking water also wasn’t that great. They turned to milder alcoholic drinks like beer as a safer alternative. Also, controlled fermentation was one way to preserve perishable foods before refrigeration existed, along with salting/ drying and pickling. A lot of our best foods came out of that, like sauerkraut, salami, pickles, and jam.
Anything with sugar or starch in it is fermentable, and can be made into alcohol. Rum is made from molasses (or sometimes, fresh sugarcane juice), and sugar canes grow in hot, tropical areas. In a hot climate and over long sea voyages, a product that is non-perishable is very helpful. Oak barrels were the most widely available large containers back then. Aging a spirit in oak gives it a rich, vanilla/ toasty flavor. Since rums were so often transported and stored in oak, it became a traditional part of the “recipe” for making rum, and is still used to this day.
And pirates, with their devil-may-care swashbuckling ways, love a good drink. :)