Determine the type of deck post and cap you have; different types of deck material will call for different methods for attaching them. For caps made of vinyl material, glue is your best option. Purchase PVC glue or another type of plastic binding glue. Use a brush to apply the glue thoroughly to the inside of the cap, but be careful not to get any glue on the cap's face as the glue could permanently damage its appearance. Place the cap firmly on the post and wipe away any runoff glue.
Wood or Composite
For wood or composite deck material you have some different options for affixing caps; you must determine which will work best for your style of deck. Use wood glue for caps that slip over the top of posts. Apply glue to the inside of the cap and place it on the post.
For other types of wood caps, use deck screws or small nails to attach them to the post. Pre-drill any holes for screws to prevent splitting or cracking them. Try to hide screws and nails by placing them on the side of the cap for a better look.
Use a screw for aluminum caps; glue will not hold. Purchase small, self-tapping screws designed for aluminum material. Attach caps with one or two screws.
Some aluminum caps will not require screws. These caps are self-locking and will snap into place on the post. Use a rubber mallet, or a hammer and block of wood (this will prevent damage to the cap), to knock the caps securely onto the post. If the cap appears crooked, keep tapping--it's probably not on all the way. Then pull the cap; secure caps will not pull off by hand.