"A well-regulated militia, being necessary to the security of a free State, the right of the people to keep and bear Arms shall not be infringed."
Like so much in the U. S. Constitution, the second amendment is open to a variety of interpretations. One that is used by many is that gun ownership is needed to protect oneself against the government.
Those who hold to this interpretation ignore Article I, Section 8, which includes the power of Congress "To provide for the calling forth the Militia to execute the Laws of the Union, suppress Insurrections and repel Invasions" and Article III, Section 2, which includes "The President shall be Commander in Chief of … the Militia of the several States when called into the actual Service of the United States".
This has happened at least twice. George Washington, as Commander in-Chief, lead forces against the insurrection of the those tax-evading participants of the Whiskey Rebellion. Old George knew what he was doing; he had been president of the Constitutional Convention. Abe Lincoln was Commander in Chief of the various militia against the insurrection of the Southern States.
If you want to have a gun to protect yourself against the government, the government has the constitutional right to call out the militia to protect itself against you.