Before the arrival of intruders from the north and east, the coastal regions of north Africa were inhabited by a number of peoples, known collectively as Berbers, related to the ancient Egyptians, and occasionally at war with them and with each other. They were also affected by the Phoenician colony to their west: Carthage, founded around 800 BC and expanding along the North African coast. They were largely nomadic, but with a few cities. The name Libya appears to derive from the Libu, one of these tribes mentioned in Egyptian sources. When Greek colonists arrived, they applied the name Libya to the territory west of the Nile valley (which included much of present-day Libya), and in later times, to the entire continent of Africa. Previously, though, the name had been used for a mythical land of peace and abundance, such as that inhabited by Homer's Lotus Eaters (Odyssey Book 9).
The Greeks
Herodotus preserves various conflicting tales about the origin of Greek colonisation in the area: the basic fact being that one Battus from the island of Thera (modern Santorini) founded a colony at Cyrene, on the Libyan coast, traditionally in 630 BC. His dynasty, the Battiads, ruled Cyrene, and its surrounding territory of Cyrenaica, until 440 BC. The native Libyans resisted spasmodically, but generally unsuccessfully, and further Greek settlers arrived (Barca was founded c. 570 BC). The ruling class lived the normal life of Greek aristocrats, including competing in chariot-races at the Olympics and other mainland games. Cyrene exported the mysterious silphium (from a plant now extinct) highly-prized both as a seasoning and miracle cure. The Pentapolis ("The Five Cities") became rich and populous. It even had its own philosophical school - the Cyrenaic School, founded by Socrates' pupil Aristippus. Unlike Socrates, though, they advocated the focused pursuit of pleasure: some of his gems!

The 6th century BC Temple of Zeus in Cyrene, Libya
Persian takeover
With the fall of Memphis in 525 BC, Cambyses' conquest of Egypt was complete. According to Herodotus:
The Egyptians after this, having been besieged for some time, surrendered. The Libyans who were their neighbours were scared by what the Egyptians had suffered, and surrendered themselves without a fight. They accepted having to pay tribute, and kept on sending gifts. The people of Cyrene and Barca [ie the Greek colonists] were just as frightened as the Libyans, and acted similarly. Cambyses was pleased with the gifts that came from the Libyans, but criticised the offerings of the Cyrenaeans - because, as it seems to me, they were too meagre.Herodotus 3.13
But Cambyses' gains needed to be reinforced later (513 BC) by Darius I. The two biggest Greek cities were constantly bickering. When Arcesilaus III of Cyrene (a descendant of Battus) was murdered by people from Barca, the Egyptians, backed by Persia, intervened militarily to find the culprit. Herodotus again:
This was the excuse. But I believe the Persian expedition was sent to conquer Libya. The peoples of Libya are numerous and diverse, and very few of them were the king's subjects. Most of them didn't give a toss about Darius.Herodotus 4.167
Barca was tricked into surrender, the ringleaders were executed, and its population was deported all the way to Bactria at the opposite end of the Persian empire.
We hear little more of Libya (dependent as we are on Greek sources) until 463/2 BC, when the Libyan king Inarus, presenting himself as a son of the last native Egyptian king before Cambyses' conquest, organised a rebellion of Libyans and Egyptians against Persian rule, and secured the backing of Athens. The revolt was successful for six years (460 - 454 BC), but after firm intervention by Artaxerxes I, ended in disaster for all concerned. Inarus was executed. The 200 strong Athenian fleet was annihilated. Only a few men escaped across the desert.
So ended the great expedition of the Athenians and their allies to Egypt.Thucydides 1.110.4
After Alexander conquered Egypt in 332 BC, and entered Cyrenaica in 331 BC, Persian rule ended. But Libya became the scene for one of Alexander's most significant acts: his journey across the desert to the oasis at Siwa, to consult the oracle of Ammon. Ammon was identified with the Greek Zeus, and Alexander subsequently began thinking of himself as son of Zeus rather than son of Philip: a significant stage in the development of his megalomania!
Back to the Greeks
Libya, along with Egypt, came under Macedonian rule, this time that of Ptolemy, Alexander's friend and commander. The Greek cities of Cyrenaica - the Pentapolis - became important centres of Greek culture: art, medicine and architecture especially, although they were no longer independent, but ruled by kings of Ptolemy's family. The last of them bequeathed his kingdom to Rome in 74 BC.
A short piece I wrote on Libya in 2011 (before Gaddafi's overthrow)