The short answer to your question is: "Dinosaurs have lived all over the planet in all kinds of habitats"
They've been around for 230 million years and have adapted to a vast number of environments. Even if we disregard birds (some of whom thrive in the middle of the Atlantic Ocean, under water, or in the snow of Antarctica) and look at just the 'classic' extinct dinosaurs, the variety of habitats is still pretty impressive.
Some dinosaurs lived at the Equator, others lived far to the north or the south. Some lived in dense rain forests, some at the shores of rivers or lakes, some lived in open plains, some lived by the seashore, some lived in sandy desserts, some lived on small islands, some lived in the trees, and some dug small tunnels in the ground like foxes.
Some dinosaurs probably lived in the mountains, but we'll never know since mountain dwelling creatures don't fossilize.
And on top of that, it seems that some dinosaurs migrated every spring and fall, just like many types of birds do today. So they wandered between different habitats.
Is there a specific kind of dinosaur, whose habitat you would like to know about?