In the beginning God created the heavens and the earth.
Does the Bible state a reason anywhere?
God created the heavens and the earth as an expression of His glory.
I think John Piper explains it nicely in Desiring God, which is available for free online. Basically, he argues that God's ultimate purpose and joy is in the display of His glory:
And to that purpose, creation is the expression of His glory:
To some, this concept might seem to put God in a light in which he seems vain, or like he is "just showing off" (as @MasonWheeler mentioned). I don't believe it does.
Although "showing off" is essentially correct, that phrase carries a negative connotation. I think that connotation comes from the fact that "showing off" is usually used to describe humans that scramble to draw attention to, and highlight their own perceived glory. The difference between these people and God is that:
On the other hand:
Earth is the dwelling place of mankind. God's decision to create mankind necessitated the creation of a dwelling place for him.
The heavens possibly include the sky, the stars and planets, and even the throne of God. The sky, stars, and planets are, of course, part of man's dwelling place.
God's throne is where the angelic beings can be in His presence, but also mankind as well.
Two Scripture references, that basically say the same thing:
As tautological as this sounds, it is true - God made everything for himself, because he wanted to.
In summary God created the Earth to bask in his Glory as it is just for him to do so. And he created the people in love of Himself. People are to be active citizens in love for themselves, and ultimately Him. And Socrates's Allegory of the cave clearly exemplifies such. Bible versus to support my claims: "Proverbs 1:5, John 3:20-21, Matthew 5: 14&16."