This is an American phrase, first recorded in the May 1922 edition of Harpers Magazine:
"Mr. Roberts knows his onions, all right."
According to World Wide Words, this had nothing to do with any Mr. Onions, but:
The crucial fact is that the expression isn’t British
but American, first recorded in the magazine
Harper’s Bazaar in March 1922. It was one of a set
of such phrases, all with the sense of knowing
one’s stuff, or being highly knowledgeable in a
particular field, that circulated in the 1920s. Others were to know one’s oats, to know one’s
oil, to know one’s apples, to know one’s eggs,
and even to know one’s sweet potatoes (which
appeared in a cartoon by T A Dorgan in 1928).
You may notice certain similarities between the
substances mentioned, most being foods and most having names that start with a vowel.
They contain much of the verbal inventiveness
and mildly juvenile wordplay that characterises
another American linguistic fad of the flapper
period, that of describing something excellent of
its kind in terms of an area of an animal’s
anatomy (elephant’s instep, gnat’s elbows and about a hundred others — see my piece on bee’s knees for more).
As with bee’s knees, one of these multifarious
forms eventually triumphed and became a
catchphrase that has survived to the present day.
The Phrase Finder agrees:
Other phrases that refer to
knowing - 'know the ropes', 'doesn't know shit from Shinola' etc. allude to specific items as
the focus of the knowledge.
Other 1920s variants of 'know
your onions' are 'know your oil/
oats/apples' etc. The only one that caught on and
is still in common use is 'know your onions'. So, why onions? Well, as the citation above asks -
why not? Explanations that relate the phrase to
knowledgeable vegetable gardeners, or even to C.
T. or S. G. Onions, are just trying too hard. 1920s
America was a breeding ground for wacky
phrases (see the bee's knees for some examples) and this is just another of those.
Edit: A tantalising snippet in Google Books shows this may have been used in 1908 in a humorous poem in The Postal Record (Volumes 21-22 - Page 27). It' shown in the summary, and is interesting as the year 1908 is also shown. Care must be taken with snippets, as they're sometimes incorrectly dated, but here it is anyway:
But, never mind; Billy knows his onions, He Is not troubled with corns or bunions. He travels along at a good, fair gait; Unless the roads are bad, he Is never late. O. 8. WHITE. WHkesbarre, January 1, 1908. West Hoboken, N. J. At the regular meeting of Branch 1065, held on January 10, 1908, it was honored by the presence of Brother Kelly, President of our National Association.
The American Heritage Dictionary of Idioms dates for dear life to the mid-1800s, although that appears to be too late by a wide margin, as I find a use from an 1815 stage play with unquestionably the same meaning as today:
Hold thee tongue: here be datur Fanny, sir, after you and Mr. Perry went away, comed runnin for dear life, and axed for Mr. Perry and when I told her he were gone, she falled down on the floor and then, sir, I picked her up in my arms, and she ha'nt spoke since.
It seems clear that for dear life was a fairly well recognized idiom by the time this play was published. I found some even earlier uses, but they mostly seem to be less idiomatic and more literal.
Best Answer
The adage 'happy wife, happy life' could be said to have appeared at least as early as 1903, in the final verse of a choice bit of doggerel titled "The Work and Wages Party", where the parallel and rhyming phrases might as well have been no more than a congeries, rather than expressing causality:
The working man's song was in the neighborhood of three other articles about labor disputes.
From there, I find no further appearances until the adage shows up in a series of real estate ads in 1958, in Abilene, Texas. Here's the earliest of the series:
This is again not necessarily more than a congeries of phrases.
In 1970, the same year the adage is claimed to have appeared as a lyric sung by Thomas Jefferson's wife in "1776; a musical play", it shows up again in a real estate ad, this time in The Morning Call of Allentown, Pennsylvania (01 Nov 1970; paywall).
Sporadic use of the adage as ad-man's fodder is not replaced by frequent use until the late 1990's (1998), when Jeff Allan (aka Jeff Allen) adopts it for the title of a filmed compilation of comedic sketches, skits and social commentary.