Susan, the ferries (which is how you should make this trip) run on a predetermined schedule, and you can purchase RT tickets at the port on the day of your trip. During high season, if not wishing to book online, you might want to buy them the day before.
The Sorrento tourism website says:
https://www.sorrentoinsider.com/en/t/sorrento/capri
"From mid-April to mid-October the hydrofoils to Capri fill up easily and there can be long lines at the departure ports. We recommend booking tickets in advance. During the winter months, ferry services to and from Capri may be suspended due to adverse weather conditions. To stay updated on any service interruptions, you can check this (link) Facebook page"