The Constitution of the United States has always been a work in progress. That's because from the very beginning, like the people who constructed it, it was far from perfect.
The Constitution originally failed to end slavery. It initially did not give the right to vote to anyone but land owners.
Women were unable to vote in the United States until 1920. Black Americans were effectively kept from voting in some states until the Voting Rights Act was finally passed in 1970.
The Second Amendment to the Constitution was part of the original Bill of Rights, adopted by a fledgling nation in December 1791 - 221 years ago.
The world was very different then. The original intent of the Second Amendment was to permit rapid deployment of a militia, which at that time was a preferred alternative to a standing army.
The idea was to allow citizens to rapidly assemble a defense in case of foreign invasion. The revolutionary war with England was certainly fresh in the minds of Americans then.
At the same time that states and the national government were considering the "right to bear arms," they were also expressing the view that a "standing army" was considered to be a threat to peace.
But it was also clearly maintained that such an army, if one was maintained, was to be strictly under civil power. From this review of language by the states at that time, there was never any thought that somehow, civilians would have a need to defend themselves from "the government."
It should be noted that the language in all cases referred to "arms," rather than "guns" or "firearms." That's because in the 1700s, arms included spears, pikes, swords and other weapons, not just firearms.
Firearms in those days were unreliable, heavy, inaccurate, difficult to maintain due to rust and corrosion, were not made to standard calibers, and were certainly not at all like the weapons of modern times.