Governments are institutions set up by societies to create and enforce laws and rules of conduct.
Modern western philosophy usually analyzes governments through some variant of social contract theory, which was developed by John Locke and Thomas Hobbes among others and seeks to describe government as a contractual agreement among the people to help create a world that is better than the “state of nature.”
Since then, political philosophers have developed a myriad of different systems for thinking about government, from the Marxist viewpoint of government as a class construct of oppression, to the Keynesian view of government as an important economic regulator.
Rationalists typically see government as a means to a greater utilitarian end. In a democracy, the government can act as the hand that directly enacts and restricts actions in accordance with popular opinion. Obviously, there are many ways this can go wrong.