Upon independence, Costa Rican authorities faced the issue of officially deciding the future of the country. Two bands formed, the Imperialists, defended by Cartago and Heredia cities which were in favor of joining the Mexican Empire, and the Republicans, represented by the cities of San José and Alajuela who defended full independence. Because of the lack of agreement on these two possible outcomes, the first civil war of Costa Rica occurred. The Battle of Ochomogo took place on the Hill of Ochomogo, located in the Central Valley in 1823. The conflict was won by the Republicans and, as a consequence, the city of Cartago lost its status as the capital, which moved to San José.
In 1838, long after the Federal Republic of Central America ceased to function in practice, Costa Rica formally withdrew and proclaimed itself sovereign. The considerable distance and poor communication routes between Guatemala City and the Central Plateau, where most of the Costa Rican population lived then and still lives now, meant the local population had little allegiance to the federal government in Guatemala. From colonial times to now, Costa Rica’s reluctance to become economically tied with the rest of Central America has been a major obstacle to efforts for greater regional integration.
Coffee was first planted in Costa Rica in 1808, and by the 1820s, it surpassed tobacco, sugar, and cacao as a primary export. Coffee production remained Costa Rica’s principal source of wealth well into the 20th century, creating a wealthy class of growers, the so-called Coffee Barons. The revenue helped to modernize the country.
Most of the coffee exported was grown around the main centers of population in the Central Plateau and then transported by oxcart to the Pacific port of Puntarenas after the main road was built in 1846. By the mid-1850s the main market for coffee was Britain. It soon became a high priority to develop an effective transportation route from the Central Plateau to the Atlantic Ocean. For this purpose, in the 1870s, the Costa Rican government contracted with U.S. businessman Minor C. Keith to build a railroad from San José to the Caribbean port of Limón. Despite enormous difficulties with construction, disease, and financing, the railroad was completed in 1890.
Most Afro-Costa Ricans descend from Jamaican immigrants who worked in the construction of that railway and now make up about 3% of Costa Rica’s population. U.S. convicts, Italians and Chinese immigrants also participated in the construction project. In exchange for completing the railroad, the Costa Rican government granted Keith large tracts of land and a lease on the train route, which he used to produce bananas and export them to the United States. As a result, bananas came to rival coffee as the principal Costa Rican export, while foreign-owned corporations (including the United Fruit Company later) began to hold a major role in the national economy and eventually became a symbol of the exploitative export economy. The major labor dispute between the peasants and the United Fruit Company (The Great Banana Strike) was a major event in the country’s history and was an important step that would eventually lead to the formation of effective trade unions in Costa Rica, as the company was required to sign a collective agreement with its workers in 1938.
Historically, Costa Rica has generally enjoyed greater peace and more consistent political stability than many of its fellow Latin American nations. Since the late 19th century, however, Costa Rica has experienced two significant periods of violence. In 1917–19, General Federico Tinoco Granados ruled as a military dictator until he was overthrown and forced into exile. The unpopularity of Tinoco’s regime led, after he was overthrown, to a considerable decline in the size, wealth, and political influence of the Costa Rican military. In 1948, José Figueres Ferrer led an armed uprising in the wake of a disputed presidential election between Rafael Ángel Calderón Guardia (who had been president between 1940 and 1944) and Otilio Ulate Blanco. With more than 2,000 dead, the resulting 44-day Costa Rican Civil War was the bloodiest event in Costa Rica during the 20th century.