Updated:

1. Point at any coordinates

/give @s minecraft:compass[lodestone_tracker={target:{pos:[100,64,-200],dimension:"minecraft:overworld"},tracked:false}]

Put the X, Y and Z in pos. With tracked:false the compass keeps pointing there even without a lodestone; with the default tracked:true it spins.

2. A named treasure compass

/give @a minecraft:compass[lodestone_tracker={target:{pos:[100,64,-200],dimension:"minecraft:overworld"},tracked:false},custom_name="Treasure"]

On 1.20.5 to 1.21.4, write custom_name='"Treasure"'. See the treasure hunt commands.

3. Nether and End targets

Set dimension to minecraft:the_nether or minecraft:the_end. In any other dimension the compass spins.

4. Move the normal compass

/setworldspawn 0 64 0

Normal compasses point to world spawn, so this turns all of them. For per-player respawn points, see the spawnpoint command.

5. Point to your last death

/give @s minecraft:recovery_compass

More ways in the death location guide.

6. Retarget the compass in your hand (Java)

/item modify entity @s weapon.mainhand {function:"minecraft:set_components",components:{"minecraft:lodestone_tracker":{target:{pos:[0,64,300],dimension:"minecraft:overworld"},tracked:false}}}

This points the held compass somewhere new, perfect for a treasure hunt where each find reveals the next spot. Wrap it in execute as @a run for everyone (1.20.5+).

7. Write the coordinates in the lore (Java)

/give @s minecraft:compass[lodestone_tracker={target:{pos:[100,64,-200],dimension:"minecraft:overworld"},tracked:false},lore=[{"text":"X 100 / Z -200","color":"gray","italic":false}]]

The lore line shows when you hover over the item, so players still know the spot if the compass spins. This form needs 1.21.5+.

8. 1.20.4 and older

/give @s minecraft:compass{LodestonePos:{X:100,Y:64,Z:-200},LodestoneDimension:"minecraft:overworld",LodestoneTracked:0b}

Troubleshooting

Check your command

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