Egypt opened Africa’s first railway, making Egypt the answer to this question.
The project began after Abbas I contracted the British engineer Robert Stephenson in 1851 to build Egypt’s first standard-gauge railway. The initial section opened in 1854 between Alexandria and Kafr el-Zayyat, on the Rosetta branch of the Nile. The line did not reach Cairo until 1856, so the question’s country is correct even though its shorthand description compresses two stages of construction.
Further expansion followed quickly. A route from Cairo to Suez was completed in 1858, creating an important modern transport link between the Mediterranean and the Red Sea before the Suez Canal opened in 1869. The railway also became the first in Africa and the Middle East, and the first in the Ottoman Empire. Morocco, Algeria, and South Africa later developed important railway systems, but none is the country associated with Africa’s first railway in 1854.