What is a command block in Minecraft?
A command block is a special block that stores one Minecraft command and runs it when it's activated – by redstone, or constantly if you set it to "Always Active". It can run almost every command an operator can type in chat: teleport players, give items, change the time, show titles or apply effects.
You can't craft or mine a command block. It only exists for operators and map makers, which is why survival players never see it in the normal inventory. Only an operator in creative mode can place, break or edit it; for everyone else it behaves like an unbreakable block.
How to get a command block
Type /give @p minecraft:command_block in chat (or give <name> minecraft:command_block in the server console) – you need operator rights for that. The block lands in your inventory, one per command; add a number at the end for more, e.g. /give @p minecraft:command_block 4.
| Command | What it does |
|---|---|
/give @p minecraft:command_block |
Gives a command block to the nearest player (when you type it, that's you) |
/give @s minecraft:command_block |
Gives it to yourself |
give Steve minecraft:command_block |
From the server console – gives it to Steve |
/setblock ~ ~ ~ minecraft:command_block |
Places a command block right where you stand |
There is also a creative tab for it: in Options → Controls, turn on "Operator Items Tab". The creative inventory then shows an "Operator Utilities" tab with command blocks and other operator blocks (structure blocks, barriers and so on). The tab only appears for players with operator permissions.
On a server you first need OP. Open the server console and type op YourName (in the console without the leading /). On Spot.gg that's the "Console" tab of the server panel. More admin commands are in our Minecraft server commands guide.
How to enable command blocks on a server
On Minecraft Java 1.21.9 and newer, command blocks are controlled by a gamerule; on 1.21.8 and older by enable-command-block=true in server.properties. In 1.21.9 Mojang removed the option from server.properties, so the right method depends on your server's version.
| Server version | How to enable command blocks | Restart needed? |
|---|---|---|
| 1.21.11 and newer (including 26.x) | gamerule command_blocks_work true |
No |
| 1.21.9 – 1.21.10 | gamerule commandBlocksEnabled true |
No |
| 1.21.8 and older | enable-command-block=true in server.properties |
Yes |
The gamerule was renamed twice during development: it arrived as enableCommandBlocks in a 1.21.9 snapshot, became commandBlocksEnabled before the 1.21.9 release and command_blocks_work in 1.21.11, when Mojang moved almost all gamerules to snake_case names. If the console replies "Unknown or incomplete command", you're using the name of another version. To check the current value, type the gamerule without true or false, e.g. gamerule command_blocks_work. All renamed rules are in Minecraft gamerules.
On Spot.gg: gamerule in the Console
On 1.21.9 and newer, open "Console" and type the gamerule line from the table above, without a slash. It works right away and is saved in the world, so it survives restarts.
On Spot.gg: enable-command-block in server.properties (1.21.8 and older)
- In the server menu click "Configuration" and open the "server.properties" tab.
- Find
enable-command-blockin the "Most commonly used" section (or type it into the search box). - Set it to
trueand click "Save changes". - Restart the server – the panel shows a "Restart now" button under the field.
The panel lists enable-command-block on every Java server, also on 1.21.9 and newer, but there the game no longer reads it – use the gamerule. Which version your server runs is shown in "Information", in the "Engine" row. The same server.properties tab holds all other options; they are explained in Minecraft server.properties.
How to use a command block
Place the block, right-click it in creative mode, type a command into the "Console Command" field, click "Done" and power it with redstone. The leading slash is optional inside a command block.
- Make sure you are OP and in creative mode:
/gamemode creative. - Place the command block and right-click (use) it to open its window.
- Type the command, for example
say Hello from a command block!. - Click Done.
- Put a button or lever on the command block and press it. The message appears in chat.
The window also has a small output box ("Previous Output") that shows the result of the last run – the first place to look when nothing happens.
Selectors: who does the command affect?
Selectors such as @p and @a decide who a command targets, and in a command block they are measured from the block, not from you. That's the most common surprise for beginners.
| Selector | Targets |
|---|---|
@p |
The nearest player to the command block |
@a |
All players |
@r |
A random player |
@s |
The executor; a command block itself is not a player, so @s alone usually finds nobody |
@e |
All entities (mobs, items, players) |
You can narrow them down with arguments, e.g. @a[distance=..5] (players within 5 blocks of the block) or @e[type=minecraft:zombie] (only zombies).
Command block types: Impulse, Chain and Repeat
Impulse (orange) runs once per activation, Chain (green) runs right after the block that points into it, and Repeat (purple) runs every game tick – 20 times a second – while it's active. You switch the type with the first button in the command block window.
| Type | Colour | When it runs | Default redstone setting |
|---|---|---|---|
| Impulse | Orange | Once each time it's activated | Needs Redstone |
| Chain | Green | When the block pointing into it has run | Always Active |
| Repeat | Purple | Every game tick while active | Needs Redstone |
Two more buttons change the behaviour:
- Needs Redstone / Always Active – "Needs Redstone" waits for a redstone signal; "Always Active" works without one.
- Unconditional / Conditional – a "Conditional" block only runs if the block behind it (the one pointing into it) ran successfully. The default is "Unconditional", which ignores the result of the previous block.
Command blocks have a direction (the arrow on their texture). Chain blocks are built in a line, each one facing the next: an Impulse or Repeat block at the start, then any number of Chain blocks. That's how one button press can run several commands in order.
Command block commands: simple examples to copy
These examples work on a vanilla Java server and only need a command block, a button, pressure plate or lever, and the right type. Replace the coordinates with your own (press F3 to see where you are).
| Goal | Block setup | Command |
|---|---|---|
| Welcome message | Impulse, button | say Welcome to the server! |
| Teleport pad | Impulse, pressure plate on top | tp @p 100 64 -200 |
| Day on demand | Impulse, button | time set day |
| Clear weather | Impulse, button | weather clear |
| Starter kit | Impulse, button | give @p minecraft:stone_sword 1 |
| Healing zone | Repeat, Always Active | effect give @a[distance=..5] minecraft:regeneration 5 1 true |
| Kill dropped items (lag fix) | Impulse, button | kill @e[type=minecraft:item] |
Tips for a smooth start:
- Repeat blocks run 20 times a second. Commands like
givein a Repeat block flood inventories within seconds; use them for effects and checks, and keep one-off actions in Impulse blocks. - Use
@pfor pads and buttons, so the command targets the player standing at the block rather than everyone. - Test in a corner of the world first, and protect the area – only operators can break command blocks, but players can still press buttons next to them.
- Chain several steps: Impulse block with
tp @p 0 80 0, then a Chain block withsay @p arrived at spawn.
Why is my command block not working?
Usually command blocks are disabled on the server, you aren't OP in creative mode, or the block isn't getting redstone. Check these in order:
- Command blocks are disabled. On 1.21.9+ set the gamerule for your version (table above); on 1.21.8 and older set
enable-command-block=trueand restart. Editingenable-command-blockon 1.21.9+ has no effect. - You can't open or place the block. You must be OP and in creative mode. The server option
op-permission-levelmust be2or higher (the default is4, so this only matters if someone lowered it). - Nothing happens on a button press. Check "Needs Redstone" vs "Always Active" and look at the "Previous Output" box – it shows errors such as a wrong item name.
- The command works in chat but not in the block. Selectors count from the block:
@sfinds nobody and@ppicks the player nearest to the block, not you. - A Chain block doesn't run. It must be pointed into by the previous block (check the arrows) and set to "Always Active"; a "Conditional" chain block also needs the previous block to succeed.
- A command from a tutorial fails. Commands change between versions – for example many gamerule names changed in 1.21.11. Check which version your server runs.
Paid Minecraft servers on Spot.gg start from $3.90 per month, and a new account can try a server free for 24 hours first – enough to build your first command block contraption.
FAQ
How do you get a command block in Minecraft?
Type /give @p minecraft:command_block as an operator. You can also turn on "Operator Items Tab" in Options → Controls and take it from the "Operator Utilities" tab in creative mode.
Can you get a command block in survival?
Not without commands. A command block can't be crafted or mined; an operator has to give it with /give, and you need creative mode to place and edit it.
How do I enable command blocks on my server?
On Java 1.21.11 and newer run gamerule command_blocks_work true in the server console, on 1.21.9–1.21.10 gamerule commandBlocksEnabled true. On 1.21.8 and older set enable-command-block=true in server.properties and restart.
Why is enable-command-block missing from my server.properties?
Since Java 1.21.9 the option no longer exists – Mojang replaced it with a gamerule. Use the gamerule for your version instead.
Do you need a slash in a command block?
No. Commands in a command block work with or without the leading /. In the server console you type them without the slash.
What do the colours of command blocks mean?
Orange is Impulse (runs once), green is Chain (runs after the previous block) and purple is Repeat (runs every tick while active).