Updated:

Ride the nearest pig

VersionCommand
Java 1.19.4 and later/ride @s mount @e[type=minecraft:pig,limit=1,sort=nearest]
Bedrock Edition/ride @s start_riding @e[type=pig,c=1]

The rider comes first and the vehicle second. Without a saddle you can sit on a pig or horse but not steer it.

Dismount

VersionCommand
Java/ride @s dismount
Bedrock/ride @s stop_riding

On Bedrock, /ride @e[type=boat,c=1] evict_riders removes everyone from a vehicle.

Make a jockey

/ride @e[type=minecraft:skeleton,limit=1,sort=nearest] mount @e[type=minecraft:spider,limit=1,sort=nearest]

Both the rider and the vehicle must be a single entity, so use limit=1. To spawn them already stacked, use Passengers:

/summon minecraft:spider ~ ~ ~ {Passengers:[{id:"minecraft:skeleton"}]}

Bedrock extras

Stack more than two mobs

Passengers can hold their own Passengers, so one /summon builds a whole tower. This spawns three slimes stacked on top of each other:

/summon minecraft:slime ~ ~ ~ {Passengers:[{id:"minecraft:slime",Passengers:[{id:"minecraft:slime"}]}]}

A chicken jockey works the same way, with a baby zombie as the rider:

/summon minecraft:chicken ~ ~ ~ {Passengers:[{id:"minecraft:zombie",IsBaby:1b}]}

Put a player in a minecart or boat

/ride @p mount @e[type=minecraft:minecart,limit=1,sort=nearest]

For boats, the entity ID depends on the version. Java 1.21.2 and later use one ID per wood type, such as minecraft:oak_boat or minecraft:spruce_chest_boat. Older versions use minecraft:boat with a Type tag.

Steering after you mount

Run commands on the vehicle or the riders

Java 1.19.4 also added execute on, which switches to the entity a player is riding, or to the entities riding something.

/execute as @a on vehicle run effect give @s minecraft:speed 10 1

This gives Speed to every mount that currently carries a player. Players who are not riding anything are skipped, so the same line also works as a "who is riding" test. Use on passengers to go the other way, for example to dismount everyone from the nearest horse:

/execute as @e[type=minecraft:horse,limit=1,sort=nearest] on passengers run ride @s dismount

Keeping a player seated

Players can always get off by pressing sneak. If a map needs them to stay seated, run the mount command again from a repeating command block, and give the vehicle NoAI:1b so it does not wander. Expect a short flicker each time the player is put back.

Common problems

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.