The area known today as Cape Town has no written history before it was first mentioned by Portuguese explorer Bartholomeu Dias in 1488. The German anthropologist Theophilus Hahn recorded that the original name of the area was '||Hui !Gais' - a toponym in the indigenous Khoe language meaning "where clouds gather." All knowledge of the previous inhabitants of the region was derived from fossil evidence and from rock art in the area.
The first Europeans to discover the Cape were the Portuguese. Bartholomeu Dias arrived in 1488 after journeying south along the west coast of Africa. The next recorded European sighting of the Cape was by Vasco da Gama in 1497 while he was searching for a route that would lead directly from Europe to Asia.
Table Mountain was given its name in 1503 by António de Saldanha, a Portuguese admiral and explorer. He called it Taboa da caba ("table of the cape"). The name given to the mountain by the Khoi inhabitants was Hoeri 'kwaggo ("sea mountain").
The area fell out of regular contact with Europeans until 1652, when Jan van Riebeeck and other employees of the Dutch East India Company (Dutch: Vereenigde Oost-Indische Compagnie, or simply VOC) were sent to the Cape to establish a halfway station to provide fresh water, vegetables, and meat for passing ships travelling to and from Asia. Van Riebeeck's party of three vessels landed at the cape on 6 April 1652. The Cape was under Dutch rule from 1652 to 1795 and again from 1803 to 1806. The group quickly erected shelters and laid out vegetable gardens and orchards, and are preserved in the Company Gardens. Water from the Fresh River, which descended from Table Mountain, was channelled into canals to provide irrigation. The settlers bartered with the native Khoisan for their sheep and cattle. Forests in Hout Bay and the southern and eastern flanks of Table Mountain provided timber for ships and houses. At this point, the VOC had a monopoly on trade and prohibited any private trade. The Dutch gave their own names to the native inhabitants that they encountered, calling the pastoralists "Hottentots", those that lived on the coast and subsisted on shellfishing "Strandlopers", and those who were hunter-gatherers were named "Bushmen".
The first wave of Asian immigration to South Africa started in 1654. These first immigrants were banished to the Cape by the Dutch Batavian High Court. These Asians helped to form the foundation of the Cape Coloured and Cape Malay populations, as well as bringing Islam to the Cape. The first large territorial expansion occurred in 1657, when farms were granted by the VOC to a few servants in an attempt to increase food production. These farms were situated along the Liesbeeck River and the VOC still retained financial control of them. The first slaves were brought to the Cape from Java and Madagascar in the following year to work on the farms. The first of a long series of border conflicts between the inhabitants in the European-controlled area and native inhabitants began in 1658 when settlers clashed with the Khoi, who realised that they were losing territory.
Work on the Castle of Good Hope, the first permanent European fortification in the area, began in 1666. The new castle replaced the previous wooden fort that Van Riebeeck and his men built. Finally completed in 1679, the castle is the oldest building in South Africa.
Simon van der Stel, after whom the town of Stellenbosch is named, arrived in 1679 to replace Van Riebeeck as governor. Van der Stel founded the Cape wine industry by bringing grape vines with him on his ship, an industry which would quickly grow to be important for the region. He also promoted territorial expansion in the Colony.
The first non-Dutch immigrants to the Cape, the Huguenots, arrived in 1688. The Huguenots had fled from anti-Protestant persecution in Catholic France to the Netherlands, where the VOC offered them free passage to the Cape as well as farmland. The Huguenots brought important experience in wine production to the Cape, greatly bolstering the industry, as well as providing strong cultural roots.
By 1754, the population of the settlement on the Cape had reached 5,510 Europeans and 6,729 slaves. But by 1780, France and Great Britain went to war against each other. The Netherlands entered the war on the French side, and thus a small garrison of French troops were sent to the Cape to protect it against the British. These troops, however, left by 1784. By 1795, however, the Netherlands was invaded by France and the VOC was in complete financial ruin. The Prince of Orange fled to England for protection, which allowed for the establishment of the Dutch Batavian Republic. Due to the long time it took to send and receive news from Europe, the Cape Commissioner of the time knew only that the French had been taking territory in the Netherlands and that the Dutch could change sides in the war at any moment. British forces arrived at the Cape bearing a letter from the Prince of Orange asking the Commissioner to allow the British troops to protect the Cape from France until the war. The British informed the Commissioner that the Prince had fled to England. The reaction in the Cape Council was mixed, and eventually the British successfully invaded the Cape in the Battle of Muizenberg. The British immediately announced the beginning of free trade.
Under the terms of a peace agreement between Britain and France, the Cape was returned to the Dutch in 1802. Three years later, however, the war resumed and the British returned their garrison to the Cape after defeating Dutch forces at the Battle of Blaauwberg (1806). This period saw major developments for the city, and can be said to be the start of Cape Town as a city in its own right. Taps and iron pipes were installed along major streets in the city. The native inhabitants were forced to declare a fixed residence and were not permitted to move between regions without written permission. The war between France and England ended in 1814 with a British victory. The British drew up a complex treaty whereby pieces of real estate were exchanged for money by various countries. The Cape was permanently taken from the Dutch by the British in return for a large sum of money. In this period, the British saw the control of the Cape as key to their ability to maintain their command in India. The Dutch government was too impoverished and depleted to argue, and agreed with the condition that they be allowed to continue to use the Cape for repairs and refreshment.
The vagrancy and pass laws of 1809 were repealed in 1829. Thus, the Khoikhoi, in theory, were equal with the Europeans. As in the rest of the British Empire, slaves - estimated to be around 39,000 in number - were emancipated in 1834. This led to the establishment of the Bo-Kaap by a Muslim community after being freed. The Cape Town Legislative Council was also established in the same year. One of the most momentous events in South African history, the Great Trek (Afrikaans: die Groot Trek), began in 1836. About 10,000 Dutch families, for various reasons, left for the north in search of new land, thereby opening up the interior of the country. Further political development occurred in 1840 when the Cape Town Municipality was formed. At its inception, the population stood at 20,016, of which 10,560 were white.
Ensuing political developments now saw gradual moves towards greater independence from Britain and towards a degree of political inclusiveness. In 1854, the Cape Colony elected its first parliament, on the basis of the multiracial Cape Qualified Franchise, whereby suffrage qualifications applied universally, regardless of race. After a long political struggle, this was followed by responsible government in 1872, when the Cape won the right to elect its own locally-accountable executive and Prime Minister. A period of strong economic growth and social development ensued, with a rapid expansion of the Cape Government Railways and other infrastructure, connecting Cape Town to the Cape's vast interior.
The discovery and subsequent exploitation of diamonds and gold in the former Transvaal region in the central highveld in the 1870s and 1880s led to rapid change in Cape Town, as well as in Cape Colony as a whole. In particular, the rise to power of the ambitious colonialist Cecil Rhodes, fueled by the new diamond industry, led to great instability. On becoming the Cape's new Prime Minister, he restricted the multiracial Cape franchise, and instigated a rapid expansion of British influence into the hinterland. A rise in inter-ethnic tensions ensued, followed by the Anglo-Boer War.
As the city of Johannesburg grew from the gold fields, Cape Town lost its position as the single dominant city in the region, but, as the primary port, it nonetheless benefitted from the increased trade to the region. The mineral wealth generated in this period laid the foundation for an industrialised society. This period marked the first incident of segregation in the city. Following an outbreak of bubonic plague which was blamed on the native Africans, the natives were moved to two locations outside of the city, one of which was near the docks and the other at Ndabeni, about six km east of the city.
The latter settlement was the start of what would later develop into the townships of the Cape Flats. In 1948, the National Party stood for election on its policy of racial segregation, later known as apartheid. After a series of bitter court and constitutional battles, the already limited voting rights of the Coloured community in Cape Province were revoked. In 1966, the once-vibrant District Six area was bulldozed and declared a white-only area. This and many similar declarations under the Group Areas Act resulted in whole communities being uprooted and relocated to the Cape Flats.
Under apartheid, the Cape was considered a "Coloured labour preference area", to the exclusion of Black Africans. The government tried for decades to remove largely Xhosa squatter camps, such as Crossroads, which were the focal point for black resistance in the Cape area to the policies of apartheid. In the last forced removal, between May and June 1986, an estimated 70,000 people were expelled from their homes.
Hours after being released from prison on 11 February 1990, Nelson Mandela made his first public speech in decades from the balcony of the Cape Town City Hall, heralding the beginning of a new era for South Africa.