Herrera was born on December 21, 1804. He entered military service in 1822 and became a lieutenant. He participated in the battles of Junín and Ayacucho against the royalists in Peru. In 1828 he was charged with conspiracy, and jailed in Bogota. Herrera escaped, was recaptured and sentenced to death, but his sentence was commuted to banishment. Upon completion of sentence, he returned to Panama in 1830 and participated in the fight against Colonel Juan Eligio Alzuru. When Alzuru was shot, Herrera was appointed Colonel Commandant General of the Isthmus of Panama.