I've found a few threads with tutorials/info here in the past. I would link to them but there are quite a few. I put "rub rail" in the search box to find them.
Unless your rail is damaged, I think you could reinstall/re-bed/re-fasten it. You would remove the black vinyl insert from the outside of the rail to get to the fasteners. I believe the original rail was riveted on and the inside ends covered with "blobs" of something like 5200 and then gelcoated over. The hull and deck should be actually joined with fiberglass tabbing, so the rub rail attachment is simply doing that: attaching the rub rail (too bad about all the holes, but...).
Were I to re-do mine, I'd likely use 316 grade stainless machine screws/washers/nuts (bedded of course) instead of rivets. I would simply leave the nuts exposed on the inside. One could use acorn nuts, especially in locations where they would be most visible or most likely to be brushed against. If removing the whole rail I would re-bed the whole thing (under the rail, not alongside its edges).
It could also be re-riveted, but typically that's done for expediency in a production setting, which you won't have doing just one boat. Still an option though.
I do have one spot on my rail which is pulling away from the boat -- it's the very end of the portside rail, where it wraps around the stern end of the lazarette. I'll likely re-attach it with machine screws/nuts. I will simply spot repair/re-bed at this point since it's only one place; but if it were more extensive or there were leaks I would remove the whole rail(s) and re-do them systematically.
Sunbeam