Some half a million years ago, Peking man lived in Zhoukoudian, in the southwestern suburbs of Beijing. The climate of that time was warmer and more humid than it is today. Forests and lakes in the area supported large numbers of living creatures. The fossil remains of Peking man, his stone tools and evidence of use of fire, as well as later tools of 18,000 years ago, bone needles and article of adornment from the age of Upper Cave Man are the earliest cultural relics on record in China today.
Some four to five thousand years ago, settlements to the southwest of Beijing were thriving on basic agriculture and animal husbandry. Story has it that the legendary Yellow Emperor (Huang Di) battled against the tribal leader Chiyou in the "wilderness of the prefecture of Zhuo."Zhuolu, a town west of present-day Beijing, is perhaps the site of the first metropolis in the area. Yellow Emperor's successor, Emperor Yao, was said to have established a legendary capital Youdu (City of Quietude) that was where the city of Ji was actually built.
During the Warring States Period (475-221BC), the Marquis of Yan annexed the territory of the Marquis of Ji, making the city of Ji his new capital. The approximate location was north of Guang'anmen Gate in present–day Beijing near the WhiteCloudTemple (Baiyunguan). Early in the third century BC, the first Emperor of Qin (Qin Shi Huang) set about conquering six states and unifying China. The city of Ji was named administrative center of Guangyang Commandery, one of 36 prefectures in China’s first feudal empire. For 10 centuries, through to the end of the Tang Dynasty (618-907), Ji remained a strategic trading and military center and the object of frequent power struggles.
Some emperors during that period -- Emperor Yang of the Sui Dynasty (581-618) and Emperor Taizong of the Tang Dynasty-left their mark on the city. Emperor Yang amassed troops and supplies at Ji for expeditions against Korea. Emperor Taizong also used the city for military training. He built the Temple for Compassion for the Loyal (Minzhongsi), which is dedicated to troops who died in battle. This temple was the precursor of the Temple of the Origin of the Dharma (Fayuansi) located outside the old walls of the city.
At the beginning of the Tang Dynasty, Ji was little different from any other large feudal cities. Several centuries later, however, when the Tang was nearing a state of collapse, the Qidans (Khitans) came from the upper reaches of the LiaoheRiver and moved south to occupy Ji and make it their second capital. They called the city Nanjing (Southern Capital) or Yanjing. Emperor Taizong of the Liao Dynasty (916-1125) carried out reconstruction projects and built palaces, which were used as strongholds from which the Qidans set out to conquer the central plains of China.