Installing NATS
Outcome: two programs on your machine — nats-server
and nats — each able to state its version, and a server
running on a port you chose with JetStream switched on.
NATS installs as two separate downloads, on purpose. The
server is the system; the CLI (nats) is one
client among many, used throughout this guide to drive
the server. Install the server once; the CLI is how you
will talk to it, test it, and administer JetStream.
The release downloads
The lab installed from the projects' official GitHub releases, unmodified:
- nats-server 2.15.2 —
nats-server-v2.15.2-linux-amd64.tar.gzfromgithub.com/nats-io/nats-server/releases, containing a single binary (about 19 MB). - nats CLI 0.5.1 —
nats-0.5.1-linux-amd64.zipfromgithub.com/nats-io/natscli/releases, containing the singlenatsbinary (about 27 MB).
There are matching archives for other systems and CPU shapes (arm64 for Raspberry Pi-class boards, macOS, Windows); pick the one with your platform in its name and check what you actually fetched before unpacking — an archive that is a few bytes long is an error message wearing a filename.
Both tools are also packaged in the usual places (the server in many Linux distributions and Homebrew, the CLI likewise); the versions there may lag the releases. This guide's transcripts are from the release binaries above, and its verification is the version check:
$ nats-server --version
nats-server: v2.15.2
$ nats --version
0.5.1
(transcript t00). If yours differ, the ideas still hold; JetStream in particular has been stable across the 2.x line for years.
Starting a server worth using
Bare nats-server listens on port 4222, the traditional
NATS port, with JetStream off. The lab started its server
with four choices made explicit — a client port and a
monitoring port it picked for itself, a name, JetStream
on, and a store directory inside the lab's own space:
nats-server -p 18084 -m 18085 -js -sd /path/to/jsdata -n labserver
-p— the client port. (On your own machine with nothing else claiming it, the default 4222 is fine; the lab used 18084 because its sandbox shares ports by assignment.)-m— the monitoring port, serving plain HTTP pages of server facts. Chapter 10 lives there.-js— switch JetStream on. Without it, chapters 8 and 9 have nowhere to stand.-sd— where JetStream keeps its files. Choose a directory you own and can back up; everything JetStream remembers lives under it.-n— a name, which turns up in logs, monitoring, and cluster gossip later. Naming servers early is a kindness to your future self.
The checks that prove it runs
Two requests to the monitoring port, from transcript t01:
$ curl http://127.0.0.1:18085/healthz
{"status":"ok"}
and /varz, which reports (among much more) the version,
the client port, that JetStream is enabled with its store
directory, the 1 MB maximum payload, and the current
connection count — zero, until your first client arrives.
The server's own log opens with its version, its name,
and the lines Starting JetStream and Listening for
client connections when it is ready.
If /healthz stays silent, the server is not running —
check its log before anything else; chapter 14 starts
there too.
Check: nats-server --version and nats --version
both answer, and a server started as above replies
{"status":"ok"} on its monitoring port. Everything after
this chapter assumes exactly that.