Anderson graduated 40th out of 56 cadets from the United States Military Academy in July 1842, and was brevetted a second lieutenant in the 1st U.S. Dragoons. He served the cavalry school for practice at the U.S. Army Barracks in Carlisle, Pennsylvania, in 1842. Anderson spent 1843 on frontier duty in the American West, serving first at Little Rock, Arkansas, and then on garrison duty at Forts Gibson and Washita, both located in the Indian Territory. His regiment escorted the U.S. Indian Agent to Red River in 1843, and then returned to Fort Washita, remaining there until 1844. Anderson was promoted to second lieutenant on July 16, 1844, and served at Fort Jesup, Louisiana, from 1844 to 1845. His regiment then joined the expedition for the military occupation of Texas in 1845, and Anderson was on recruiting duty in 1846.