Many factors came together to lead to the development and location of the first cities. However, the growth of different cities did not all follow the exact same course of events.
In many cases, a favorable location played a prominent role in the development of a larger settlement that eventually became a city. People settled in areas that were easily protected from enemies and that provided ease of transportation for purposes of trade. Locations close to the mouth of a river, at the junction of two rivers, or near a naturally protected seaport were highly desirable.
In order to support the population of a city, food and shelter had to be available. Locations close to agricultural developments, possibly with areas for hunting game, or near good fishing supported the increased population that contributed to the development of a city. Plentiful wood, clay or sand for making bricks or adobe, or other materials for constructing dwellings was essential.
As more people came to this desirable location that provided food, shelter, trade, allies in times of war, and other assets of living in community, needs arose for persons to fill specialized functions - businesses and trades and services came into being, with support from those in the community working at other functions. As people settled and became farmer/business persons instead of nomadic herder/gatherers, time became available for education, arts and crafts for recreation instead of survival, and for leisure.
In different proportions, all of these factors contributed to the development of cities as a pattern for settlement.