Born in New York City, Barry graduated from the United States Military Academy in 1838, 17th in his class of 45 cadets. He was commissioned a brevet second lieutenant in the 4th U.S. Artillery, transferring to the 2nd U.S. Artillery a few weeks later. He was stationed near the Canada–US border, then later took part in the Mexican–American, Seminole, and the Kansas-Missouri Border Wars.