1726, "morbid longing to return to one's home or native country, severe homesickness considered as a disease," Modern Latin, coined 1688 in a dissertation on the topic at the University of Basel by scholar Johannes Hofer (1669-1752) as a rendering of German heimweh "homesickness" (for which see home + woe).
From Greek algos "pain, grief, distress" (see -algia) + nostos "homecoming," from neomai "to reach some place, escape, return, get home," from PIE *nes- "to return safely home" (cognate with Old Norse nest "food for a journey," Sanskrit nasate "approaches, joins," German genesen "to recover," Gothic ganisan "to heal," Old English genesen "to recover"). French nostalgie is in French army medical manuals by 1754.
Originally in reference to the Swiss and said to be peculiar to them and often fatal, whether by its own action or in combination with wounds or disease.
[Dr. Scheuzer] had said that the air enclosed in the bodies of his countrymen, being in Æquilibrium with a rare and light air that surrounds them, was overloaded in lower countries with an air more dense and heavier, which compressing and obstructing the capillary vessels, makes the circulation slow and difficult, and occasions many sad symptoms. [Account of the publication of "Areographia Helvetiæ" in New Memoirs of Literature, London, March 1726]
By 1830s the word was used of any intense homesickness: that of sailors, convicts, African slaves. "The bagpipes produced the same effects sometimes in the Scotch regiments while serving abroad" [Penny Magazine," Nov. 14, 1840]. It is listed among the "endemic diseases" in the "Cyclopaedia of Practical Medicine" [London, 1833, edited by three M.D.s], which defines it as "The concourse of depressing symptoms which sometimes arise in persons who are absent from their native country, when they are seized with a longing desire of returning to their home and friends and the scenes their youth ...."
It was a military medical diagnosis principally, and was considered a serious medical problem by the North in the American Civil War:
In the first two years of the war, there were reported 2588 cases of nostalgia, and 13 deaths from this cause. These numbers scarcely express the real extent to which nostalgia influenced the sickness and mortality of the army. To the depressing influence of home-sickness must be attributed the fatal result in many cases which might otherwise have terminated favorably. ["Sanitary Memoirs of the War," U.S. Sanitary Commission, N.Y.: 1867]
Transferred sense (the main modern one) of "wistful yearning for the past" is recorded by 1920, perhaps from such use of nostalgie in French literature. The longing for a distant place also necessarily involves a separation in time.
parting salutation, 1860, of unknown origin, perhaps from a German idiom (compare German parting salutation adieu so lange, the full sense of which probably is something like "farewell, whilst (we're apart)"); or perhaps from Hebrew shalom (via Yiddish sholom). Some have noted a similarity to Scandinavian leave-taking phrases, such as Norwegian Adjø så lenge, Farvel så lenge, Mor'n så lenge, literally "bye so long, farewell so long, morning so long;" and Swedish Hej så länge "good-bye for now," with så länge "for now" attested since 1850 according to Swedish sources. Most etymology sources seem to lean toward the German origin. So long (adv.) "for such a long time" is from late Old English.
Earlier guesses that it was a sailors' corruption of a South Pacific form of Arabic salaam are not now regarded as convincing. "Dictionary of American Slang" also adds to the list of candidates Irish slán "safe," said to be used as a salutation in parting. The phrase seems to have turned up simultaneously in America, Britain, and perhaps Canada, originally among lower classes. First attested use is in title and text of the last poem in Whitman's "Leaves of Grass" in the 1860 edition.
An unknown sphere, more real than I dream'd, more direct, darts awakening rays about me — So long!
Remember my words — I may again return,
I love you — I depart from materials;
I am as one disembodied, triumphant, dead.
Whitman's friend and fan William Sloane Kennedy wrote in 1923:
The salutation of parting — 'So long!' — was, I believe, until recent years, unintelligible to the majority of persons in America, especially in the interior, and to members of the middle and professional classes. I had never heard of it until I read it in Leaves of Grass, but since then have quite often heard it used by the laboring class and other classes in New England cities. Walt wrote to me, defining 'so long' thus: "A salutation of departure, greatly used among sailors, sports, & prostitutes — the sense of it is 'Till we meet again,' — conveying an inference that somehow they will doubtless so meet, sooner or later." ... It is evidently about equivalent to our 'See you later.' The phrase is reported as used by farm laborers near Banff, Scotland. In Canada it is frequently heard; 'and its use is not entirely confined to the vulgar.' It is in common use among the working classes of Liverpool and among sailors at Newcastle-upon-Tyne, and in Dorsetshire. ... The London Globe suggests that the expression is derived from the Norwegian 'Saa laenge,' a common form of 'farewell,' au revoir. If so, the phrase was picked up from the Norwegians in America, where 'So long' first was heard. The expression is now (1923) often used by the literary and artistic classes.