Do you need a visa to enter Peru? Most likely not. It will depend on your nationality, check here
However, most visitors to Peru do not need to apply beforehand for a visa. When you arrive at the airport in Lima and go through customs, the officer will ask you how long you will be in Peru for. You will be given a tourist visa for the number of days of your trip to Peru. Most custom officers will add a few extra days to your visa so that it is not the exact length of your trip. Emergencies sometimes happen while changes to travel plans happen more frequently. Custom officials want to make sure you have a little wriggle room in case you decide to stay a few extra days in Peru.
The maximum number of days for a tourist visa in Peru is 183 days, or six months in other words.
At the moment, Peru is changing their visa restrictions, making it harder for visitors to stay longer than the 183 days on a tourist visa in the country. In the past, many tourists had entered the country on a tourist visa for 183 days, left the country before the visa ended (e.g. to Bolivia or another close border) and re-entered a couple of days later to get another permission for 183 days. However, now there is a big chance that you will not be allowed to enter Peru again, once you have already stayed 183 days as a tourist in Peru in the same year.
If you do wish to stay longer than 6 months in Peru on a tourist visa, there is the possibility to simply overstay your visa and pay a certain amount of money for each day you have stayed longer upon existing the country. This is a short-term option, however it is not advisable.
If you are planning to stay more than 183 days in Peru, it is advisable to apply for a work visa or student visa beforehand.
Should you even intend to move to Peru for business reasons or work, you may qualify for a business or work visa. A work visa will grant you a residency card (Carnet de Extranjería) and you will be treated as a foreign resident in Peru. This status comes with perks such as free entrance to some ruins and museums or reduced pricing.
You can find more information on visas here