Introduction
This tutorial teaches you how to install a NATS server directly on Debian-based linux (not via Docker).
Overview
The installation consists of multiple steps each of which will be explained in detail. Those steps are as follows:
- Create a user with name
natswho belongs to the groupnats. - Download the latest NATS release build.
- Unzip the folder and copy it to
/usr/bin. - Add NATS to
systemd. - Run the NATS server and confirm it is working.
- Enable it, so it can run at startup.
Step 1: Create the user nats
In order to add a user, we will use the useradd command, like so.
sudo useradd -s /bin/bash -d /home/nats/ -m -G sudo nats
To add a password for the user (not really needed, just a standard practice):
sudo passwd nats
Step 2: Download NATS
As per the documentation, one can download NATS by using the following shell command.
curl -L https://github.com/nats-io/nats-server/releases/download/v2.10.22/nats-server-v2.10.22-linux-amd64.zip -o nats-server.zip
Note that you may want to change the version of NATS if there are newer releases.
Step 3: Add NATS to /usr/bin
This step is straightforward. First, open the file explorer and unzip NATS.
Now copy the unzipped folder to /usr/bin
sudo cp nats-server/nats-server-v2.10.22-linux-amd64/nats-server /usr/bin
Step 4: Add NATS to systemd
This one is a little tricky, but this guide simplifies it for you.
Create
/etc/nats-server.conf. No need to add content to it, since it is only there for customization and overriding the default behavior.Create
/etc/systemd/system/nats.serviceand add the following content to it.
[Unit]
Description=NATS Server
After=network-online.target ntp.service
[Service]
PrivateTmp=true
Type=simple
ExecStart=/usr/bin/nats-server -c /etc/nats-server.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s SIGINT $MAINPID
User=nats
Group=nats
# The nats-server uses SIGUSR2 to trigger using Lame Duck Mode (LDM) shutdown
KillSignal=SIGUSR2
# You might want to adjust TimeoutStopSec too.
[Install]
WantedBy=multi-user.target
- Save and exit.
Windows Subsystem for Linux
For WSL users, please make sure the user nats has the access permission on /usr/bin/nats-server. Here is how:
Change the user to nats.
su - nats
Then add read and execute permissions to that folder.
sudo chmod +rx /usr/bin/nats-server
Step 5: Run the NATS server
This one is easy. We reload the daemon and then run NATS.
sudo systemctl daemon-reload
sudo systemctl start nats
To confirm that it is running, run systemctl status nats, and you should get that it is active.
Step 6: Enable NATS
To enable NATS which would run it at startup, simply run the command below:
sudo systemctl enable nats
Conclusion
This simple tutorial ensures that the installation of NATS on Debian-based linux is smooth and easy. Let me know below if you have any questions or inquiries about it.
Happy building!


Top comments (2)
I think Nats is also available as snap package, do you know of any drawbacks using that?
There should be none as long as the clients can communicate with it. The command to run it could be slightly different though. This includes parameters such as JetStream. Double check the documentation.