The idea for Jerusalem's temple originated with King David. Although he wanted to build it, God only allowed him to gather building materials for it. It would be left to David's son Solomon to construct the house of God in Jerusalem (2Samuel 7:4-6, 12-13). God tells us why David could not build the temple.
6 He (David) summoned his son Solomon and commanded him to build a temple for the LORD God of Israel. 7 David told his son Solomon, 'I had my heart set on building a temple for the name of the LORD, my God. 8 But the LORD spoke his word to me by saying, ‘You have caused a lot of bloodshed and fought in a lot of wars. You must not build a temple for my name because you have caused so much bloodshed in my presence.'' (1Chronicles 22:6-8, GWT)
Solomon began his reign over Israel in 970 B.C. and began work on the temple four years later (966 - 965 B.C.). He built "the house of God" on the east side of Jerusalem where Abraham was to offer Isaac as a sacrifice (Genesis 22:1-14). The structure was completed in 959 - 958 B.C.
After Solomon's death Israel split into two major pieces - the Northern Ten Tribes of Israel and the Kingdom of Judah. The Northern kingdom lasted until 723 B.C. The kingdom of Judah lasted until 586 B.C. when it was conquered by Babylon. It was Babylon's King Nebuchadnezzar who burned, pillaged and destroyed the temple in Jerusalem and carried all of its treasures away to Babylon.
The second (or Herod's) temple was built in the same location as the first. When Herod the Great became king of Judea the unfinished structure had stood for about five hundred years. Herod, desirous of gaining the favor of the Jews, proposed to rebuild it.
Ultimately, the need for an earthly sanctuary in Jerusalem was fulfilled and brought to completion by the sacrifice of Jesus Christ, which ended the Old Covenant and the need for a physical priesthood. Under the New Covenant, the spiritual temple of God is in heaven where Jesus Christ is High Priest and has superseded any physical one on earth.