Many countries have a different system for choosing a prime minister,
but I will assume that you are asking specifically about the process
used to choose the prime minister in the United Kingdom. The prime
minister begins as a member of parliament, but will then be appointed
head of their party by party members. When a general election is called,
they will then go up against the leaders of other parties to try and
gain the most votes. If there is a majority for their party, they will
become prime minister.