Updated:

The basic command

/summon minecraft:lightning_bolt ~ ~ ~5

This strikes five blocks south of you. ~ ~ ~ would hit you directly.

Strike players or mobs

/execute at @p[name=!YourName] run summon minecraft:lightning_bolt ~ ~ ~
/execute at @e[type=minecraft:zombie,distance=..10] run summon minecraft:lightning_bolt ~ ~ ~

execute at moves the position to the target first. The first line strikes the nearest other player, the second every zombie within 10 blocks.

Strike where you are looking

/execute at @s run summon minecraft:lightning_bolt ^ ^ ^10

^ uses the direction you face, so this hits 10 blocks ahead. See ~ and ^ coordinates.

What lightning changes

StruckBecomes
CreeperCharged creeper (bigger explosion)
PigZombified piglin
VillagerWitch
MooshroomSwitches between red and brown
Nearby blocksMay catch fire

To avoid fires near builds on Java 1.21.10 and earlier, run /gamerule doFireTick false. The fire rule was renamed in 1.21.11, so pick it from the /gamerule suggestions there.

Repeated strikes

A repeating command block strikes 20 times a second and lags badly. For a show, trigger an impulse block with a button or chain a few blocks.

Thunderstorms and Channeling

/weather thunder starts a storm with natural lightning. A trident with Channeling, thrown during a storm, calls lightning on the target: /give @p minecraft:trident[enchantments={channeling:1,loyalty:3}] (Java 1.21.5+).

Common questions

Check your command

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