Have someone hold the carpet tight, straight and flat as you cut it to keep the edge as straight as possible.
Cut the carpet with a very sharp utility knife or special carpet knife to reduce fraying as much as possible. Berber carpet, for example, is best cut with a row cutter instead of a utility knife.
Turn the carpet over, if possible, or turn the edge up so the wrong side is facing you.
Use a paint stirrer, spatula or popsicle stick to spread a layer of carpet glue along the edge.
Let the glue dry thoroughly before laying it back down on the floor.