It was originally passed down orally, with many different versions and variations emerging over time.
One of the earliest known written versions is a collection of English fairy tales by James Orchard Halliwell-Phillipps in 1853, titled "The Popular Rhymes and Nursery Tales of England."
However, even before that, other versions existed, likely influenced by earlier European folk tales.