How to dye carpets
Do you mean a rug or a carpet attached to your home? I'd use RIT type dye in a bucket to dye a rug.
Here's one using paint.
I would hesitate to dye a wall to wall carpet of a large area rug. If it has been used or walked on, there is often unseen particles in or on it and would make your color uneven. If a small rug, then go with Morgan's suggestion of Rit dye in a pail.
Dying wall to wall is no longer recommended. If get it too wet fue to it being on pad it could mold.