You need a patron. Someone who can get you an "in" on a ship as a (depending on age) captain's servant, or (probably later) a midshipman. You might appear on the ship's muster roll as a seaman to give you the "sea time" you need to qualify as a lieutenant. If you have a relative or family friend, this would be best. Nelson, for example, had an uncle who was a Captain.
You'll need to have some money behind you as you won't be paid much and you'll need to buy your own uniform and equipment, books, sextant etc. You'd also need some money to contribute to your mess bills, or otherwise you'll be living off the same rations as the ordinary seamen and marines.
After 6 years at sea, you can sit the examination for Lieutenant - you'll have to produce certificates of your age and good character and journals of your time at sea as well. The exams are difficult, a lot is the mathematics of navigation, so study hard. Many men never succeed in passing them at all.
If you pass, you'd better still have a patron, or have ingratiated yourself with your captains over the years because passing is no guarantee of a ship. You might end up on half-pay although chances of a ship are much better in war time than peace.
If you get a ship, you'd better hope you get one with some chance of promotion. Either by seniority or by demonstrating extraordinary courage and diligence. If you're unlucky you'll end up in the West Indies, where sickness especially Yellow Fever is rampant. Mind you, you might get an acting promotion if no one else is left.
If you haven't been shipwrecked, killed or maimed in battle or fallen out with the Powers that Be, if your patron(s) can help, if you can curry favour with the Admiralty, you might be given a chance in a small ship, carrying mail or supplies. You just have to hope that zeal, luck, patronage and skill can carry you further.
Just to add a book recommendation. The Wooden World by Nicholas Roger 1986 is an excellent and accessible history of the Royal Navy at this time and documents the careers of many in similar situations to your question.