He studied in the College of San Carlos in Lima. When José de San Martín arrived in Peru in 1820, Salaverry left college despite the opposition of his father, and made his way to Huaura Province, where he volunteered to join the general and his forces. San Martin enlisted him as a cadet of the battalion of Numancia, in which he took part in the campaign against the Spaniards. After the establishment of the republic of Peru, Salaverry rose rapidly in the army. At the age of twenty-eight, he had obtained the rank of general.
When the garrison of Callao revolted in January 1835, against then President Luis Orbegoso, and pronounced in favor of La Fuente, Salaverry defeated the insurgents. Orbegoso appointed him governor of the fortress. But on February 23, Salaverry rose in arms against the government. After Orbegoso abandoned Lima, Salaverry occupied the capital and proclaimed himself "Supreme Chief of the Republic". In a few months he had possession of the south, and Orbegoso retreated with a small force to the northern provinces.
He sought the intervention of Andrés Santa Cruz, leader of Bolivia, with whom Orbegoso concluded a treaty. Soon after, the Bolivian army invaded Peru, and Salaverry retreated to the city of Arequipa. On 7 February 1836, his forces were totally routed to Socabaya, a district of the city.
After wandering for several days, Salaverry surrendered to General Miller, who delivered him to Santa Cruz. Contrary to the customs of war against enemies who surrender, Santa Cruz ordered the execution of Salaverry. This led to popular resistance and ultimately defeat of the Peru–Bolivian Confederation led by Santa Cruz.