Offer Why us? How it works?
Guide

Minecraft Command Block: How to Get It, Enable It and Use It

A command block runs a Minecraft command on its own, whenever redstone powers it or even every tick. It's how map makers build teleport pads, welcome messages, mini-games and spawn effects without plugins. This guide shows how to get a command block, how to turn command blocks on for a server in every Minecraft version and how to set up your first ones.

Updated: 9 min read
Table of contents
  1. What is a command block in Minecraft?
  2. How to get a command block
  3. How to enable command blocks on a server
  4. On Spot.gg: gamerule in the Console
  5. On Spot.gg: enable-command-block in server.properties (1.21.8 and older)
  6. How to use a command block
  7. Selectors: who does the command affect?
  8. Command block types: Impulse, Chain and Repeat
  9. Command block commands: simple examples to copy
  10. Why is my command block not working?
  11. FAQ
  12. How do you get a command block in Minecraft?
  13. Can you get a command block in survival?
  14. How do I enable command blocks on my server?
  15. Why is enable-command-block missing from my server.properties?
  16. Do you need a slash in a command block?
  17. What do the colours of command blocks mean?

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)

  1. In the server menu click "Configuration" and open the "server.properties" tab.
  2. Find enable-command-block in the "Most commonly used" section (or type it into the search box).
  3. Set it to true and click "Save changes".
  4. 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.

  1. Make sure you are OP and in creative mode: /gamemode creative.
  2. Place the command block and right-click (use) it to open its window.
  3. Type the command, for example say Hello from a command block!.
  4. Click Done.
  5. 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 give in a Repeat block flood inventories within seconds; use them for effects and checks, and keep one-off actions in Impulse blocks.
  • Use @p for 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 with say @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=true and restart. Editing enable-command-block on 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-level must be 2 or higher (the default is 4, 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: @s finds nobody and @p picks 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).

Other guides