Before you switch
Take a manual backup first. Version changes aren't always reversible, especially jumping forward several versions at once.
Changing versions
Open the Version tab and select a platform (Vanilla, Paper, Fabric, Forge, or another option), then pick your game version and build. Click Install. The panel automatically selects the matching Java version for you. Your worlds, plugins, and configs stay in place.
For detailed steps, see Installing Server Software from the Version Tab.
Upgrading forward
Minecraft handles opening an older world in a newer version fine. The game upgrades chunk data automatically the first time it loads.
Downgrading
Going backward is riskier. A world saved in a newer version can contain blocks or data the older version doesn't understand. Restore from a backup taken before the original upgrade if you need to go back.