Getting Started
Verified against
v2.14.2. Commands assume a Unix shell with Go 1.25+ or Docker, plus thenatsCLI.
Prerequisites
- Go 1.25 or newer to build from source, or Docker to run the published image.
- The
natsCLI for publishing and subscribing from the command line.
Install
go install github.com/nats-io/nats-server/v2@latestYou can instead download an official release binary, or run the published image:
docker run -p 4222:4222 natsA first working setup
The shortest path to a running server and a delivered message. The default client port is 4222, and the monitoring HTTP endpoint is enabled with -m 8222 (nats.io about).
Start the server with JetStream enabled and monitoring on.
bashnats-server -js -m 8222In a second terminal, subscribe to a subject.
bashnats sub fooIn a third terminal, publish a message to that subject.
bashnats pub foo hello
The subscriber prints the received message on foo.
Verify it works
Check the monitoring endpoint for server health and connection counts:
curl http://localhost:8222/varzThe nats sub foo terminal should also show the hello payload it received, which confirms end-to-end delivery.
Where to go next
For durability, replay, key/value, and object storage, read the JetStream docs and Consumers. For clustering, gateways, leaf nodes, and security hardening, see the official documentation rather than re-deriving it here (nats.io about).