The short answer
Longhouses were built in many parts of the world, and not all of them are connected. The best-known cases are in Europe, from the Neolithic onward; in Scandinavia and the Norse world; in Britain and Ireland; in northeastern North America, among the Haudenosaunee and other Iroquoian peoples; and in Southeast Asia, especially on Borneo. People in these places arrived at a long, narrow, single-roof design separately.
Neolithic Europe
Some of the earliest longhouses known to archaeologists come from the first farming communities of central Europe, roughly 7,000 years ago or more. Their remains are mostly postholes and soil stains. Settlements of this kind have been found across a broad band of the continent, from the Danube region toward the Rhine and beyond. Longhouses continued to be built in various forms in later prehistory, so the type is not limited to the earliest farmers.
Scandinavia and the Norse world
In the Viking Age and the centuries around it, longhouses and long halls were common in Scandinavia. The Norse also carried the building tradition to places they settled, including Iceland and Greenland, and the site at L’Anse aux Meadows in Newfoundland has remains of buildings in a Norse style. In treeless or timber-poor places, builders used turf and stone for walls.
Britain and Ireland
A medieval longhouse tradition developed in parts of Britain, with people and livestock sharing one roofed building. Some examples are found in upland areas and have been studied through both excavation and surviving standing buildings. The idea of a house and byre together was widely understood in rural communities well into later centuries.
Northeastern North America
In what are now New York, Ontario, Quebec and neighboring areas, the Haudenosaunee and the Wendat, among other Iroquoian-speaking peoples, built bark-covered longhouses in villages that were often palisaded. These are probably what most English speakers picture first when they hear the word. The Haudenosaunee Confederacy itself uses the longhouse as a symbol of its member nations living under one roof.
People of the Pacific Northwest built large plank houses that can also be long and shared by many people. They are a separate tradition with their own materials, designs and meanings, and are usually called plank houses rather than longhouses.
Southeast Asia
On Borneo and in nearby areas, longhouses are still lived in. They are usually raised on posts and have a long communal veranda with family units side by side. Peoples such as the Iban and the Orang Ulu are often associated with this style, and details differ from group to group.
Why the same form appears in different places
A long building can be extended as a household grows, is simple to frame with a row of posts, and keeps a group together. Where people lived in extended families or kept animals close, a single long roof made sense. Similar solutions can arise without any cultural link. For more on the early history of shelter in general, see our pieces on when humans first made homes and on the first buildings in history.