Guinea pigs are very docile animals, and it’s very rare for them to bite without cause. Lots of guinea pigs will mouth their owners whilst they are being held, and this could be to get salt of your fingers or just to see if you’re edible! This shouldn’t hurt, and isn’t a sign of aggression, just curiosity.
Guinea pig’s teeth are one of their very few defensive tools, so if your guinea pig really does bite you, then it’s likely that they’re afraid of you. You can rectify this by teaching your guinea pig that it shouldn’t be afraid of you, and that it can expect affection, kindness and treats when you come towards it.
Guinea pigs only usually bite if they are afraid - try to figure out why your guinea pig feels this way and take steps to make it feel more comfortable
To stop your guinea pig biting, you need to figure out what's making it bite in the first place.
Do you smell of something that your guinea pig will likely be afraid of, such as cats and dogs? Try wearing very clean clothes, and thoroughly wash your hands before you attempt to hold them. It may be a good idea to wear gloves to offer you some protection, and if you choose to do this then be sure to wash these too. Alternatively, try and reduce the stress your guinea pig is under. Are they in a very noisy area? Do they feel threatened by other pets?
Next, try to understand what’s making your guinea pig bite you. One of the principle things that causes biting is pain. Are you sure you’re not holding your guinea pig too tightly? If this behaviour has recently developed, then your guinea pig might have an illness or injury that’s causing them pain, so try to give them a check over to see if they need to go to the vet. If they have a disease such as mange, this can make handling extremely painful for your pet, and it has no other way of telling you not to pick it up.
Similarly, if your guinea pig wants to be put down so it can go to the loo, it may nibble you to tell you this. When you put your guinea pig back, carefully watch it to see if it just needed to satisfy a particular bodily need.
Other potential reasons for biting are to do with how your guinea pig is being kept. If it chews the bars of its hutch then this can indicate that your guinea pig is lonely and wanting to go and find a friend. If you only have one guinea pig, then even if you’re the most affectionate owner in the world then it will still be lonely without a guinea pig companion. If you’re sure you’re guinea pig isn’t lonely, then one final potential cause is testosterone - if your guinea pig isn’t neutered, then you might want to consider this course of action, but be aware that there is no guarantee that it will produce any change in behaviour.