The story
The term was popularized by a (fictional) pirate shanty in the novel Treasure Island (1883) by Scottish writer Robert Louis Stevenson (1850–1894) – see the quotation – but appears in earlier songs of sailors. The term is possibly a variant of yo-he-ho, apparently a short form of yo-heave-ho (“a repetitive call made to synchronize workers performing some collective physical labour, such as hauling on a rope”).
Etymology from Wiktionary, CC BY-SA 4.0.