You have a free ship at every Promotion up to rear amiral and one free ship costume change.
For those you get tokens that replace the regular currency.
For more ships you need to collect dilithium.
Though nobodoy actually buys dilithium ships.
At endgame you can either buy new ships from the c-store for Zen, which are in essence real world money but but can be exchanged for in game dilithium with other players, or buy a mirror universe ship on the EC exchange, which is the cheapest option, but not the best ships.
Other methods include a range fleet refit ships for fleet credits, dilithium and upgrade modules (Zen or EC).
And last but not least more exotic lockbox ships, which depend on a lot of money in a high risk gamble or very expensively on the EC Exchange.
Don't bother with those until you are at endgame and settled in fir good.
The ship you get for free at level 40 is good enough for all PvE endgame.
Try to use your leveling experience to sample different ship types to find out which you like best.
I recommend science vessel at Lt Commander, Cruiser at Commander and Escort at Captain and then pick the type you liked best for admiral.
Or, if you, like recommended eearlier, play all 3 factions, you can one class and shiptype per faction to get an even better feel fir what you prefer