Guinea pigs, as you see them today, are extensively domesticated. Since this change has been going on for thousands of years, the domestic guinea pig is distant enough to be its own species. Wild cavies do still live in the historic natural habitat of guinea pigs, but you won’t find one that looks like the pet.
Geography
Guinea pigs came from South America, specifically the Andes Mountains. Peru and Bolivia are the natural habitats of guinea pigs. Civilizations across the Andes domesticated these cavies and then traded with them.

Habitat
The ancestors of domestic guinea pigs were flexible as to where they lived. Everything from grasslands to forest edges to rocky terrain was fair game. Since guinea pigs are herbivores, they needed access to as much food as possible.
In the natural habitat of guinea pigs, they lived in burrows. While the guinea pigs may have dug their own, they could also take over ones set up by other animals. They would then forage for up to 20 hours a day, though the burrows protected them when predators were most active.
The Wild Diet
Guinea pigs are herbivores, then and now. They are also primarily foragers. Most of the native grasses are perfect for guinea pigs. Additionally, a guinea pig’s nose is sensitive enough to help them determine how fresh plants are and whether they are poisonous. That’s a handy sniffer.
Most guinea pigs didn’t actually drink much water. Instead, they get most of their water from the plants they eat. In a domestic situation, your guinea pigs do not have that much access to fresh and live plants.
Social Groups
Wild guinea pigs lived in groups. These groups were typically familial, with up to ten adults. This grouping offered guinea pigs protection. It also helps the guinea pigs being social. Your guinea pig still uses a variety of noises to communicate.

Domestication
Guinea pigs were domesticated somewhere between 5000 and 7000 years ago. The various cultures from the region kept the guinea pigs as a food source. However, guinea pigs also evolved other cultural purposes, including religious meanings. Over time, there were fewer guinea pigs in their natural habitat.
Generally, guinea pigs lived in the kitchen and allowed free rein. They took on a household pet role as well. Guinea pigs were not typically bought in many cultures. Instead, they tended to be gifted on special occasions. These included weddings, births of children, and to new trade partners.
The Spanish brought guinea pigs back to Europe. No one is precisely sure how guinea pigs got their name since they are not from any form of Guinea. Theories range from the animals costing a guinea to their taste. Regardless, the name has stuck at this point.
Over time, selective breeding has distanced your domestic guinea pig from its wild relatives. There are no wild guinea pigs like the ones in your home. There are, however, wild cavies, including the giant capybaras.