New to Minecraft, keep spawning in a dark cave, how do I get out?

Solution 1:

That's very unlucky.
An easy solution could be to generate another world and hope to spawn in a better place.

Otherwise, you could use Minecraft commands.

You can change the location where a player respawns after dying to any coordinates in the game with the /spawnpoint command.

In Minecraft Java Edition, the syntax to reset the spawn point for a player to a new location is:

/spawnpoint [targets] [pos]

Definitions

  • targets is optional. It is the name of a player (or a target selector) whose spawn point you wish to change. If you don't specify a player, the spawn point for the player running the command will be changed.
  • pos is optional. It is the x y z coordinate to use for the spawnpoint. If you don't specify a coordinate, the command will use your current position in the game.

There should be also a generic /setworldspawn

/setworldspawn <x> <y> <z>

Use /setworldspawn by itself to set the spawn point for all players to the point you’re currently at. Use /setworldspawn <x> <y> <z> with x y z coordinates to set a new spawn point for all players.