He became captain of merchant ships that carried out activities between Puntarenas and Panama, although in 1821 he was accused in court of not rendering accounts properly to one of the owners.
From March to June 1819 he was part of a detachment for the coastal defense of the Costa Rican Pacific, under the orders of Captain Don Salvador de Oreamuno.
Upon his return to Costa Rica, he represented Alajuela in a town delegate board in February 1823 and spoke out in favor of a republican system of government.
On April 5 of 1823, at the Battle of Ochomogo, his troops defeated the royalist forces and then occupied the city of Cartago, then capital of Costa Rica.
Once this group was reunited, under the presidency of José María de Peralta, Ramírez handed him power on April 16, 1823 .