Hundreds of millions of years ago, the Alterans lived in another galaxy on the evolutionary path to Ascension. Over time, two factions arose within the Alteran peoples; one faction was dedicated to scientific endeavors and the physical aspects of Ascension, the other faction was dedicated to religious study and the spiritual aspects of Ascension. The religious faction came to call themselves 'Ori' while the scientific faction continued to refer to themselves as 'Alteran'.
Eventually the friction between the factions escalated to open conflict and the Ori went full religious crusade on the Alterans, trying to exterminate them entirely. Because the Ori were the more numerous faction at this point, the Alterans faced a war of attrition that they knew they could not win, so instead they used their scientific superiority to build a spaceship and run away. (This happened somewhere between 50 million and 100 million years ago.)
Approximately 50 million years ago, the fleeing Alterans arrived at the Milky Way. There they colonized the planets of Dakara and Terra, established the Stargate network, invented ZPMs and spread a variety of outposts throughout the galaxy for whatever random-ass projects they felt like investigating. Many of these projects were never completed for a variety of reasons, the most prominent example of which being the Destiny and Seed Ships; a project to automatically propagate the Stargate network throughout the universe for later exploitation, which never went anywhere because the Alterans abandoned their material stuff when they figured out Ascension. This was also the time period when the Alterans formed an alliance with the Asgard, Nox and Furlings.
Approximately 5 to 10 million years ago, a virulent plague struck the Milky Way (believed to have been sent by the pre-ascended Ori in an attempt to wipe out the Alterans). The plague basically gutted the entire Milky Way of life, destabilizing planetary biospheres as it attempted to genocide the Alterans. Unable to cure the plague, even with time travel (which is why that time travel device exists), the Alterans built themselves a big ole city-ship called Atlantis and did what they always do when confronted with the unwanted consequences of their actions; they ran away, this time to the Pegasus galaxy. (Not all of them fled though; some stayed behind to fight the plague, the ones that stayed behind eventually built and fired the Dakara Superweapon, repairing all the ecosystems the plague had destroyed by turning them into healthy Canadian pine-forest.)
In Pegasus they went back to their usual SCIENCE! experiments, and at approximately 11,000 BC one of those experiments went hilariously wrong: Fearing that Ascension might be impossible, a group of Alterans began a series of experiments with the goal of achieving biological immortality. For reasons known only to themselves, they decided that the way to run these experiments was to kidnap 100 humans of each gender from around the galaxy and attempt to hybridize them with an unusual arthropod native to Pegasus known as the Iratus bug, which had a unique method of feeding involving consuming its preys 'life force' directly to extend its own life.
99 of the males and 9 of the females survived the experiments and became what would later come to be known as the Wraith, unexpectedly they
also developed telepathic abilities, which they used to trick the guards of the facility and escape into the wild with the failsafe weapon that was intended to kill them if they went rogue, and a stolen ZPM.
The Alterans chased the fledgling Wraith around Pegasus for awhile, but eventually lost them thanks to the Wraith using their (at the time unknown) telepathic abilities to steal various ships and equipment. They also found a really big mollusc on one of the worlds they hid on, which would later become the basis of their bioengineered Hive Ships.
Overconfident and arrogant, the Alterans kept throwing ships at the Wraith and the Wraith kept stealing them, eventually managing to collect a nice hoard of ZPMs which they used to power a
cloning facility, stamping out new Wraith drones by the thousands. This sudden surge in Wraith numbers completely threw the Alterans for a loop, and the Alterans found themselves on the losing end of
another war of attrition. This time, rather than just run away immediately, the Alterans attempted to fight back by building their own mass-produced army, combining their nanite technologies with their construction drones (aka Replicators) to create the Asurans, and in a moment of
sheer fucking genius they decided to hard-code the most powerfully virulent aggression code they could come up with into their nanite von-neumann machines so as to ensure they would fight the Wraith with everything they had.
The Asurans were not happy about the aggression code and begged the Alterans to remove it, but the Alterans were desperate and stupid and the code was part of the fail-safes preventing the Asurans from rebelling against the Alterans, however the code rendered the Asurans psychotically unstable even at the best of times, and so the Alterans concluded that the Asurans were not the solution that they had been hoping for, deleted all references to the project from their databases and glassed Asuras itself to destroy the nanites. (Unsurprisingly, some of the nanites survived and replicated back to full force.)
With the Wraith winning and their counter-strike a failure, the Alterans attempted diplomacy with the Wraith, which failed miserably. Faced with the unwanted consequences of their own actions once again, the Alterans did the thing and ran away, returning to Earth in hope that the plague had burned itself out by now. This was approximately 10,000 BC, when primitive humanity on Earth, having been left to their own devices for 5 - 10 million years, were just starting to figure out that if they took the seeds of an edible plant, planted it somewhere and looked after it as it grew, they could then harvest the edible parts for a reliable long-term food source!
Having apparently grown something resembling a conscience after the whole thing with the Wraith, the Alterans decided that conquering humanity and raising up their empire once again in the name of SCIENCE! was not an acceptable course of action. As they had figured out how to make Ascension work by this point, even to the point of 'forcefully' Ascending through Ascension Machines, the Alterans once again split into two factions; one faction Ascended and began twiddling their thumbs, or whatever the fuck it is Ascended do when refusing to interact with the material world. The other faction intermingled with primitive humanity and primitive humanity did to the Alterans as it had done to its other cousins that had evolved over the last few million years; they had lots and lots of dirty primate sex with them and popped out legions of hybrid babies, to 'set a path to future civilization' or something. (Personally I think that last part is bullshit, the Alterans were just sick and tired of their SCIENCE! projects blowing up in their faces and decided to take a vacation and bang some primitives.)
Unfortunately, neither of these two groups bothered to investigate the rest of the Milky Way after returning, and thus completely failed to notice that a bunch of parasitic snakes had discovered some Alteran tech lying around in ~22,000 BC and were busily building an intergalactic empire of slaves. This is especially ironic, as the Goa'uld discovered Earth around the same time that the Alterans returned, but by the time the Goa'uld (specifically, Ra) showed up on Earth in force the dirty primate sex faction had all grown old and died or Ascended, and the Ascended faction had decided on their 'no interference' policy. So when Ra conquered Egypt some time around ~10,500 BC, rather than do anything to clean up their mess, the Alterans decided to just not do that and, in fact, not do anything really.
And that's about it; Merlin later descended for awhile to build the Sangraal because the Ori had also figured out how to Ascend and their method was better than the Alteran method in the sense that it made the Ori more powerful, meaning that the Alterans could not fight the Ori on equal ground and thus would need a cheat code, but that's another story.