When enabled, everyone in the LAN session, you included, can run cheat commands such as /gamemode, /give and /tp. This is the same switch as Allow Cheats on the Open to LAN screen. Left off, the argument defaults to false.
The chosen mode applies to players joining over LAN. Your own game mode does not change.
The command accepts 0 to 65535, but ports below 1024 are reserved on most systems, so pick something higher; 25565, the default Minecraft server port, is the classic choice. The port must not be in use by another program. Left on automatic, the game picks a free port for you and prints it in chat.
Run from chat in your own singleplayer world with cheats enabled. Minecraft picks a free port and announces it in chat: Local game hosted on port <number>.
Quick rule: /publish shares the world you are already playing; it does not create a standalone server. The world is only joinable while you stay in it, and it works once per session: running it again reports that the game is already hosted. To switch individual players after they join, use the Gamemode Command Generator.
/publish opens the singleplayer world you are playing to everyone on your local network. It is the chat version of the Open to LAN button, with three optional arguments the button does not bundle into one step: whether commands are allowed, which game mode joining players get, and which port the game listens on.
When you run the command, Minecraft turns the integrated server behind your singleplayer world into a LAN host. Other players on the same network see the world appear on their Multiplayer screen within a few seconds and can join it like any server. Nothing is uploaded anywhere: the world stays on your machine, and it is only joinable while you remain in it.
The command carries the owners permission level, so only the world owner can run it, and only with cheats enabled. It exists exclusively on the integrated singleplayer server; dedicated servers and Realms do not have it. Typical uses are quick co-op sessions at home, LAN parties, classrooms, and testing custom maps with a second account on the same network.
The generator above builds the exact command for your setup: tick the cheats box, pick a game mode for joiners, optionally set a fixed port, and copy the result into chat.
The full form of the command is /publish [<allowCommands>] [<gamemode>] [<port>]. Every argument is optional, but they are positional and fill in from the left: you can run /publish on its own, with one argument, with two or with all three, but you cannot set a port without also giving allowCommands and a game mode first.
The three-argument form was added in Java Edition 1.19.3. Before that, /publish only accepted an optional port; the generator above switches to the old syntax automatically when you select an older version.
Five ready-to-paste commands covering the common setups. Run them from chat in your own world with cheats enabled:
/publish
Opens the world on a random free port with commands blocked for the session and the world's current game mode kept. The port appears in chat.
/publish true
Same automatic port, but everyone in the LAN session can run cheat commands. The classic quick co-op setup at home.
/publish false creative
Joining players are put in Creative while cheat commands stay blocked, so guests can build freely without switching modes themselves.
/publish true survival 25565
Cheats on, joiners in Survival, hosted on the fixed port 25565 so friends can Direct Connect to your local IP at a known address every time.
/publish false adventure 40000
An adventure map session on port 40000: joiners cannot break or place blocks freely and nobody can cheat their way past the map.
Without a port argument, Minecraft asks the operating system for any free port and prints it in chat: Local game hosted on port 51234. That is fine when everyone joins through the automatic LAN discovery on the Multiplayer screen, because nobody has to type the number. A fixed port matters when discovery fails and players need to Direct Connect: with /publish true survival 25565 the address is always the host's local IP plus :25565, the same every session.
The command accepts any port from 0 to 65535, but in practice stay above 1023: lower ports are reserved for system services on most machines and the LAN game will fail to start if the port is taken or blocked. Common choices are 25565 (the default Minecraft server port) or anything in the high tens of thousands.
To find the host's local IP for Direct Connect, run ipconfig on Windows or ifconfig on macOS and Linux and look for the address that starts with 192.168 or 10. If the world still does not appear, check that the host's firewall allows Java, and remember that LAN means local: friends on a different network need a real server or a transfer to one instead.
/publish opens the singleplayer world you are currently playing to your local network, the command version of the Open to LAN button in the pause menu. Anyone on the same network can then join from their Multiplayer screen. The world is only joinable while you stay in it; quitting the world ends the session, and no separate server process is created.
Run /publish true. The first argument is allowCommands: true lets everyone in the LAN session run cheat commands such as /gamemode, /give and /tp, while false keeps them blocked. Note that you need cheats enabled in your own world to run /publish in the first place; if they are off, use the Open to LAN screen once instead.
By default Minecraft picks a random free port each time and announces it in chat as Local game hosted on port followed by the number. Add the port argument to /publish to use a fixed one instead. The command accepts 0 to 65535, but stay above 1023 because lower ports are reserved by the operating system; 25565, the default Minecraft server port, is the usual pick.
LAN worlds are only visible to devices on the same local network, so everyone must be on the same router or Wi-Fi. If the world does not show up automatically, use Direct Connect with the host's local IP address plus the port from chat, for example 192.168.1.20:25565. A firewall blocking Java or Minecraft on the host machine is the other common cause. Players outside your network cannot join a LAN world at all.
No. The command only exists on the integrated server that runs singleplayer worlds, so it is not available on dedicated servers or Realms. It also carries the owners permission level, meaning only the world owner with cheats enabled can run it.
There is no unpublish command. The LAN session ends when you leave the world or close the game, and reopening the world starts it private again. Running /publish a second time in the same session does nothing except report that a multiplayer game is already hosted on the current port.
Sending players to a real server instead? Or browse more Minecraft tools: