Fencing your garden becomes important if you have animals that may destroy the plants. The best time to fence the garden is before you plant, so animals can't damage plants that might not be able to be replanted, due to grow-time restrictions. You should also fence the garden if you live in an area that has deer, fowl, loose dogs, armadillos, raccoons and other animals that tend to go for "easy food."
Mark the fence line around the garden. Leave at least 18 inches between the fence and the outside edge of the garden, so that the animals cannot push the fence in far enough to get to the plants, or push their snouts in through the fencing to eat the plants.
Dig the postholes for the fence posts. If you have problems with large animals, such as deer, or stronger animals, such as armadillos, put the posts 4 feet apart. If you want to keep out rabbits, dogs and other animals that are not likely to "test" the fencing, put the posts 6 feet apart.
Set the posts into the postholes. Backfill with soil. If you want a more permanent fence (which is also sturdier), put some scrap rock (broken cement, pavers, stones, whatever you have) in the bottom of the hole to help hold the post up. Pour about 12 inches of quick-set cement into the hole, then add enough water to wet the cement all the way through. Do not add too much, else it becomes a soupy mess and will not set. Allow the cement to dry according to the instructions on the package. Fill in the rest of the hole with soil.
Unroll the fencing. Staple the wire or plastic fencing to the first post. Pull the fencing to the next post. Make sure it is pulled tightly between the posts. Staple the fencing to the second post. Work in this manner from post to post. You could use wire ties for plastic fencing. If you are using metal posts, hook the fencing to the tabs on the posts, or use wire ties to attach the fencing.
Hang the gate by attaching the hinges and gate hardware to the gate. Set the gate on a support (no higher than 2 inches off the ground). Attach the hinges to the fence post so that the gate swings out. Attach the rest of the gate lock hardware to the opposite post.