The order of events
I think you're confusing what Barbossa knew when he first encountered the book, and what he knew when he's on the island with Carina.
So I'll list it chronologically:
Barbossa encounters the book. He sees that there is a precious stone in the book, and likely keeps the book for that reason.
Barbossa leaves his daughter at the doorstep of the orphanage. He left her the book (including the stone) because it is his gift to her. And likely, the stone is given as a financial gift, so that Carina doesn't grow up to be poor.
Carina grows up, knows the book, and figures out that there's a puzzle to be solved. In the meanwhile, Barbossa is off being an archetypical pirate.
Carina is the first to recognize that the stone is more than just a decoration, it is actually relevant in order to find the island. She uses the stone to read hidden information.
Coincidentally, Barbossa joins the plot again. He recognizes the book, and remembers that there was a precious stone in the book's cover. Carina then explains how she used the stone to read the hidden information.
Barbossa and Carina show up at the island. Carina is the one to spot the location that she needs to run to.
Barbossa then figures out that the stone must be used to complete the cluster. He figures this out on the spot.
Direct responses to your question
However, prior to that the ruby was stuck in the journal for years, and before that, it was in Barbossas' posession.
That's not correct. The stone has always been in the book. Barbossa encountered the book (with the stone already in it). Barbossa never owned the stone by itself. It came with the book.
As the book is Galileo's, and the stone is relevant to find the hidden island that Galileo talks about in his own book, it stands to reason that Galileo is the one who attached the stone to the book, because it's the key to finding the island.
It's also important to notice that Barbossa never realized that the stone was anything other than a valuable gem. He was not aware of it being the key to a puzzle.
The movie does explain that you need to use the ruby to find the location of the island (that houses the trident).
Carina is the one who figures that out. Barbossa had no idea.
But, to his credit, when he's on the island with Carina, Barbossa is the one to figure out that they must use the stone to complete the cluster.
But if Barbossa had the ruby, it's because he (or someone else) took the gem from the Island, therefore would have access to the trident.
Galileo is likely the one who took the stone from the island. As he writes about the trident, he is obviously aware of its existence. Since his book contains hidden information about how to find the trident, Galileo obviously knows where the trident is.
It's highly likely that a person who writes about the existence of a mythical item and its precise location, must have been there and seen it.
The book also contains the stone, which is key to finding the hidden information in the book. That must mean that Galileo must have had the stone in his possession, because how could he otherwise craft a puzzle that can only be solved by the stone, if he does not have the stone in his possession?
Galileo left the book (with the stone) specifically so others could find the island. He made sure the island's location would not be lost, but also not easily found (because he encrypted it in a puzzle).