Had it not been for the building of the railroads in the 1840s, Ayer may not have been established. Originally called South Groton, the town thrived as tanneries, vinegar factories, sawmills, and other industries settled in the area. The rapid economic development and population growth led to the formation of the Town of Ayer in 1871, named for Dr. James Cook Ayer, a producer of hair tonic and patent medicines who had donated money to the town. Ayer thrived, becoming a rail hub for transporting goods and passengers. In 1917, the War Department leased local land to build a new Army training area, Camp Devens, and its opening greatly boosted both Ayer's population and economy. The name changed from Camp Devens to Fort Devens in 1931. Since the closing of Fort Devens in 1996 and the loss of the local support- and service-oriented economy, Ayer has relied on its manufacturing economy to grow and thrive with help from the new commercial and industrial complex at the former Fort Devens site. In addition to Pan Am Southern railroad facilities, Ayer is home to Cain's food products, the Pepsi Bottling Company, and other manufacturing facilities.