If you start with a pair, and are unlucky enough to suffer a bereavement you can usually reintroduce another guinea pig to your single one. If you do just keep a single guinea pig then they can derive company from a soft toy the same size as themselves, or you can give then a mirror, that way they see another guinea pig all day but get to keep all the food for themselves!
If you do buy a male and female, intentionally or otherwise, they will be capable of breeding from 3-4 wks of age. They will need to be kept separate until the male is old enough to be castrated, and the earliest this can be done is at 4 months of age.
What about guinea pigs and rabbits?
Although there are exceptions to every rule, and you may know of someone who keeps a rabbit and guinea pig together, this is generally not a good idea. A rabbit can easily hurt a guinea pig with its powerful back legs, even unintentionally, should it stamp its feet and kick the guinea pig by mistake. They also have different dietary requirements, guinea pigs need lots of vitamin C and rabbit food does not contain any. Finally the rabbit can carry a bacterial infection called Bordetella which does not affect the rabbit, but might make the guinea pig very sick if it catches it.