Typically these are installed with a a bolt and a rubber barrel that goes in the bar with a nut on the other side of rubber barrel inside the bar. When the bolt is tightend it squeezes the barrel which expands against the insides of the bar. To install these prior to inserting the bolt/barrel/nut tighten the bolt to create the squeeze on the rubber barrel just a little bit before putting it in the hole. Also add a little spit before sliding it in.

This helps in most situations similar to this as well.

Once its in tighten the bolt and you should be able to get it firmed up so it doesnt spin in the hole. If that doesnt work try less or more

and

When removing it make sure you dont loosen the bolt all the way otherwise the nut can fall into your handlebars which can be a pain to fish out. Not that this has ever happened to me I can just predict these things sometimes.
