For a long time, this situation was taken care of via attrition (officers leaving the navy before they reached high rank). For every hundred ensigns (O-1, the lowest officer rank) entering service, about 90 will stay and make it to O-4 (Lieutenant Commander), usually after about nine years of service. About 67 of those ensigns will eventually get to serve as XO (executive officer, the number two officer on a ship) after 10-12 years of service. Some 69 of those ensigns will make it to O-5 (Commander), where it first becomes possible to command a ship (a frigate or destroyer.) About 38 of those hundred ensigns will get such a command, usually after 18-20 years of service, and for about 18 months. About 22 of those ensigns will make it to O-6 (Captain) after 20-21 years of service. But only 11 of those ensigns (now captains) will get a major seagoing command (cruiser, destroyer squadron). Officers who do well commanding a ship will often get to do it two or three times before they retire after about 30 years of service.
The new navy solution is to officially recognize a career path for officers who will never command a ship. Taking a lot of people out of the competition will improve the quality of those who are there, as many naval officers has skills more suited to shore based jobs (Antiterrorism/Force Protection, Anti-submarine warfare, Missile Defense, Mine Warfare Specialist, Shore Installation Management, Strategic Sealift.) The non-ship careers will still lead to commands, but they will be ashore. Not as glamorous as the traditional sea command, but now worth more in the competition for admiral rank (O-7 to O-10.)
The U.S. Navy is now openly dealing with a serious problem; that many officers will never have an opportunity to command a chip. Traditionally, commanding a ship was the pinnacle of a naval officers career. Currently there are 8,000 officers in the ranks O-3 (Lieutenant) to O-6 (Captain.) These are the ranks that can command ships (although O-3s command very small ones.) But the navy only has about 300 warships to command.