It takes one year for the earth to go around the sun, but one year was already this long when they didn't even know that the earth revolves around the sun at all. So how did they figure it out?
Originally a year would be noticed as the time between two winters (or two harvests, two annual floods etc), although the exact number of days might not be known with any accuracy.
As people start to observe the sun more carefully, it would be noticed that the position of sunrise and sunset move regularly. Stonehenge and other ancient monuments seem aligned to midwinter sunset or midsummer sunrise. Since this would allow one to predict the seasons, it would have been very useful.
More careful observations led to the geocentric model, in which the sun takes just over 365 days to move around the Earth once relative to the background stars. The length of the year was known to be about 365.25 days since the times of the ancient Egyptians.
There are several ways to measure a year. The time it takes for Earth to complete one orbit around the sun is called a sidereal year or 365.256363 days, and though it is a valid definition of a year, it is not the one our calendars measure, which is a tropical year. A tropical year is defined "as the period of time for the mean ecliptic longitude of the Sun to increase by 360 degrees," and is 365.24219 days in length. One way to think of the tropical year is the length of time it takes for the sun to complete its north-south journey through our sky.
There is a decent discussion of the various definitions of a year at Wikipedia. It's worth a read if you're interested.