MacGregor joined the British Army at 16, the youngest age it was possible for him to do so, in April 1803. His family purchased him a commission as an ensign in the 57th (West Middlesex) Regiment of Foot, probably for around £450. MacGregor's entrance to the military coincided with the start of the Napoleonic Wars following the breakdown of the Treaty of Amiens. Southern England was fortified to defend against a possible French invasion; the 57th Foot was at Ashford, Kent. In February 1804, after less than a year in training, MacGregor was promoted without purchase to lieutenant—an advancement that usually took up to three years. Later that year, after MacGregor had spent some months in Guernsey with the regiment's 1st Battalion, the 57th Foot was posted to Gibraltar.