Libya's history involves its rich mix of ethnic groups, including the indigenous Berbers/Amazigh people. Amazigh have been present throughout the entire history of the country. For most of its history, Libya has been subjected to varying degrees of foreign control, from Europe, Asia, and Africa.

The history of Libya comprises six distinct periods: Ancient Libya, the Roman era, the Islamic era, Ottoman rule, Italian rule, and the Modern era.

Prehistoric and Amazigh Libya

Tens of thousands of years ago, the Sahara Desert, which now covers roughly 90% of Libya, was lush with green vegetation. It was home to lakes, forests, diverse wildlife and a temperate Mediterranean climate. Archaeological evidence indicates that the coastal plain was inhabited by Neolithic peoples from as early as 8000 BCE. These peoples were perhaps drawn by the climate, which enabled their culture to grow, subsisting on the domestication of cattle and the cultivation of crops.Federal Research Division of the Library of Congress, (1987), "Early History of Libya" , U.S. Library of Congress. Retrieved 11 July 2006.

Egyptian inscriptions from the Old Kingdom are the oldest available documentation of the Berber people. The inscriptions record Berber tribes raiding the Nile Delta. Rock paintings at Wadi Mathendous and the mountainous region of Jebel Acacus are the best sources of information about prehistoric Libya, and the pastoralist culture that settled there. The paintings reveal that the Libyan Sahara contained rivers, grassy plateaus and an abundance of wildlife such as giraffes, elephants and crocodiles.Oliver, Roland (1999), The African Experience: From Olduvai Gorge to the 21st Century (Series: History of Civilization), London: Phoenix Press, revised edition, pg 39.

The onset of the Piora Oscillation's intense aridification resulted in the "green Sahara" rapidly transforming into the Sahara Desert. Dispersal in Africa from the Atlantic coast to the Siwa Oasis in Egypt seems to have followed, due to climatic changes which caused increasing desertification.

The African ancestors of the Amazigh people are assumed to have spread into the area by the Late Bronze Age. The earliest known name of such a tribe is that of the Garamantes, who were based in Germa, southern Libya. The Garamantes were a Saharan people of Berber origin who used an elaborate underground irrigation system; they were probably present as tribal people in the Fezzan by about 1000 BCE, and were a local power in the Sahara between 500 BCE and 500 CE. By the time of contact with the Phoenicians, the first of the Semitic civilizations to arrive in Libya from the East, the Libu, Garamantes, Berbers and other tribes that lived in the Sahara were already well established.

Phoenician and Greek Libya

The Phoenicians were some of the first to establish coastal trading posts in Libya, when the merchants of Tyre (in present-day Lebanon) developed commercial relations with the various Berber tribes and made treaties with them to ensure their cooperation in the exploitation of raw materials.Herodotus, (c.430 BCE), "'The Histories', Book IV.42–43" Fordham University, New York. Retrieved 18 July 2006.Federal Research Division of the Library of Congress, (1987), "Tripolitania and the Phoenicians" , U.S. Library of Congress. Retrieved 11 July 2006. By the 5th century BCE, the greatest of the Phoenician colonies, Carthage, had extended its hegemony across much of North Africa, where a distinctive civilization, known as Punic, came into being. Punic settlements on the Libyan coast included Oea (later Tripoli), Libdah (later Leptis Magna) and Sabratha. These cities were in an area that was later called Tripolis, or "Three Cities", from which Libya's modern capital Tripoli takes its name.

In 630 BCE, the Ancient Greeks colonized Eastern Libya and founded the city of Cyrene.Federal Research Division of the Library of Congress, (1987), "Cyrenaica and the Greeks" , U.S. Library of Congress. Retrieved 11 July 2006. Within 200 years, four more important Greek cities were established in the area that became known as Cyrenaica: Barce (later Marj); Euhesperides (later Berenice, present-day Benghazi); Taucheira (later Arsinoe, present-day Taucheria); Balagrae (later Bayda and Beda Littoria under Italian occupation, present-day Bayda); and Apollonia (later Susa), the port of Cyrene.History of Libya , The History Files. Retrieved 29 September 2011 Together with Cyrene, they were known as the Pentapolis (Five Cities). Cyrene became one of the greatest intellectual and artistic centers of the Greek world, and was famous for its medical school, learned academies, and architecture. The Greeks of the Pentapolis resisted encroachments by the Ancient Egyptians from the East, as well as by the Carthaginians from the West.

Achaemenid and Ptolemaic Libya

After the victory of Cambyses II in Battle of Pelusium in 525 BCE, his Persian army overran Cyrenaica and it remained under Persian rule for the next two centuries. Alexander was greeted by the Greeks when he entered Cyrenaica in 331 BCE, and Eastern Libya again fell under the control of the Greeks, this time as part of the Ptolemaic Kingdom. Later, a federation of the Pentapolis was formed that was customarily ruled by a king drawn from the Ptolemaic royal house.

Roman Libya

After the fall of Carthage, the Romans did not immediately occupy Tripolitania (the region around Tripoli), but left it under control of the Berber kings of Numidia, until the coastal cities asked and obtained its protection.Bertarelli (1929), p. 202. Ptolemy Apion, the last Greek ruler, bequeathed Cyrenaica to Rome, which formally annexed the region in 74 BCE and joined it to Crete as a Roman province. During the Roman civil wars Tripolitania (still not formally annexed) and Cyrenaica sustained Pompey and Marc Antony against respectively Caesar and Octavian.Bertarelli (1929), p. 417. The Romans completed the conquest of the region under Augustus, occupying northern Fezzan ("Fasania") with Cornelius Balbus Minor.Bertarelli (1929), p. 382. As part of the Africa Nova province, Tripolitania was prosperous, and reached a golden age in the 2nd and 3rd centuries, when the city of Leptis Magna, home to the Severan dynasty, was at its height. On the other side, Cyrenaica's first Christian communities were established by the time of the Emperor Claudius but was heavily devastated during the Diaspora Revolt,Rostovtzeff (1957), p. 364. and almost depopulated of Greeks and Jews alike,Cassius Dio, lxviii. 32 and, although repopulated by Trajan with military colonies, from then started its decadence.

Regardless, for more than 400 years Tripolitania and Cyrenaica were part of a cosmopolitan state whose citizens shared a common language, legal system, and Roman identity. Roman ruins like those of Leptis Magna and Sabratha, extant in present-day Libya, attest to the vitality of the region, where populous cities and even smaller towns enjoyed the amenities of urban life—the forum, markets, public entertainments, and baths—found in every corner of the Roman Empire. Merchants and artisans from many parts of the Roman world established themselves in North Africa, but the character of the cities of Tripolitania remained decidedly Punic and, in Cyrenaica, Greek. Tripolitania was a major exporter of olive oil,Rostovtzeff (1957), p. 335. as well as a center for the trade of ivory and wild animals conveyed to the coast by the Garamantes, while Cyrenaica remained an important source of wines, drugs, and horses. The bulk of the population in the countryside consisted of Berber farmers, who in the west were thoroughly "romanized" in language and customs.Heuser, Stephen, (24 July 2005), "When Romans lived in Libya" , The Boston Globe. Retrieved 18 July 2006. Until the 10th century the African Romance remained in use in some Tripolitanian areas, mainly near the Tunisian border.Tadeusz Lewicki, "Une langue romane oubliée de l'Afrique du Nord. Observations d'un arabisant", Rocznik Orient. XVII (1958), pp. 415–480.

The decline of the Roman Empire saw the classical cities fall into ruin, a process hastened by the Vandals' destructive sweep though North Africa in the 5th century. The region's prosperity had shrunk under Vandal domination, and the old Roman political and social order, disrupted by the Vandals, could not be restored. In outlying areas neglected by the Vandals, the inhabitants had sought the protection of tribal chieftains and, having grown accustomed to their autonomy, resisted re-assimilation into the imperial system.

When the Empire returned (now as East Romans) as part of Justinian's reconquests of the 6th century, efforts were made to strengthen the old cities, but it was only a last gasp before they collapsed into disuse. Cyrenaica, which had remained an outpost of the Byzantine Empire during the Vandal period, also took on the characteristics of an armed camp. Unpopular Byzantine governors imposed burdensome taxation to meet military costs, while the towns and public services—including the water system—were left to decay. Byzantine rule in Africa did prolong the Roman ideal of imperial unity there for another century and a half however, and prevented the ascendancy of the Berber nomads in the coastal region. By the beginning of the 7th century, Byzantine control over the region was weak, Berber rebellions were becoming more frequent, and there was little to oppose Muslim invasion.Rodd, Francis. "Kahena, Queen of the Berbers: A Sketch of the Arab Invasion of Ifrikiya in the First Century of the Hijra" Bulletin of the School of Oriental Studies, University of London, Vol. 3, No. 4, (1925), 731–2

Islamic Libya

Tenuous Byzantine control over Libya was restricted to a few poorly defended coastal strongholds, and as such, the Arab horsemen who first crossed into the Pentapolis of Cyrenaica in September 643 CE encountered little resistance. Under the command of 'Amr ibn al-'As, the armies of Islam conquered Cyrenaica, and renamed the Pentapolis, Barqa. They took also Tripoli, but after destroying the Roman walls of the city and getting a tribute they withdrew.Bertarelli (1929), p. 278. In 647 an army of 40,000 Arabs, led by Abdullah ibn Saad, the foster-brother of Caliph Uthman, penetrated deep into Western Libya and took Tripoli from the Byzantines definitively. From Barqa, the Fezzan was conquered by Uqba ibn Nafi in 663 and Berber resistance was overcome. During the following centuries, Libya came under the rule of several Islamic dynasties, under various levels of autonomy from Umayyad, Abbasid and Fatimid caliphates of the time. Arab rule was easily imposed in the coastal farming areas and on the towns, which prospered again under Arab patronage. Townsmen valued the security that permitted them to practice their commerce and trade in peace, while the Punicized farmers recognized their affinity with the Semitic Arabs to whom they looked to protect their lands. In Cyrenaica, Monophysite adherents of the Coptic Church had welcomed the Muslim Arabs as liberators from Byzantine oppression. The Berber tribes of the hinterland accepted Islam, however they resisted Arab political rule.