Rosemary is native to the dry, limestone-rich coastal scrublands of the Mediterranean, the maquis and garrigue ecosystems where thin, alkaline soils and summer drought select for plants that concentrate volatile oils as defense against herbivory and UV radiation. The genus name Rosmarinus derives from Latin ros (dew) and marinus (sea), describing its habitat on sea cliffs where morning fog provides much of its moisture.

The plant's cognitive association is among the oldest in Western herbalism. Ancient Greek students wore rosemary garlands during examinations, and the herb was placed on graves as a symbol of remembrance. Dioscorides documented rosemary as a warming herb for digestive and nervous complaints in De Materia Medica (first century CE). Medieval European herbalists classified it as a cephalic, a plant acting specifically on the head and brain. Shakespeare referenced this tradition directly when Ophelia says in Hamlet, "There's rosemary, that's for remembrance."

Arab traders brought rosemary cultivation technology into Spain during the Moorish period, where it became entrenched in both culinary and medicinal traditions. Queen Elizabeth of Hungary reportedly used an alcohol-based rosemary extract, "Hungary Water", as a rejuvenating tonic in the 14th century, making it one of the earliest documented hydroalcoholic botanical preparations in European herbalism.