The sun actually does not rise or set; it is only perceived as rising or setting because of a person's vantage point on the surface of the Earth. This perception of the sun rising and setting is due to the rotation of the Earth itself.
The Earth spins as it orbits the sun in the vacuum of space. Because of this rotation, only part of the Earth's surface is illuminated by the sun at any time. As a point on Earth rotates beyond the reach of the sun's light, an observer at that point sees the sun setting as the night sky emerges. When rotation brings that point back into the sun's light, the observer sees what appears to be the sun rising.