The sun rises in the east and sets in the west due to the rotation of the Earth on its axis. However, the exact direction of sunrise and sunset can vary slightly depending on your location and the time of year due to the Earth's tilt on its axis and its orbit around the sun.
For example, during the summer solstice, the sun rises furthest to the northeast and sets furthest to the northwest as seen from the northern hemisphere, while during the winter solstice, it rises furthest to the southeast and sets furthest to the southwest.
Also, if you are located near the equator, the sun will appear to rise and set almost directly to the east and west. However, as you move further north or south from the equator, the angle at which the sun rises and sets will change, and it will appear to move along a more north-south axis.