> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nats-io/nats-server/llms.txt
> Use this file to discover all available pages before exploring further.

# Binary Installation

> Install and run NATS Server from pre-compiled binaries

NATS Server is distributed as a single, self-contained binary with no external dependencies. This makes it easy to download, install, and run on any platform.

## Download Locations

Official NATS Server binaries are available from:

* **GitHub Releases**: [github.com/nats-io/nats-server/releases](https://github.com/nats-io/nats-server/releases)
* **Official Website**: [nats.io/download](https://nats.io/download)

### Latest Version

Download the latest stable release:

<CodeGroup>
  ```bash Linux (amd64) theme={null}
  curl -L https://github.com/nats-io/nats-server/releases/latest/download/nats-server-v2.10.0-linux-amd64.tar.gz -o nats-server.tar.gz
  tar -xzf nats-server.tar.gz
  cp nats-server-v2.10.0-linux-amd64/nats-server /usr/local/bin/
  ```

  ```bash macOS (Apple Silicon) theme={null}
  curl -L https://github.com/nats-io/nats-server/releases/latest/download/nats-server-v2.10.0-darwin-arm64.tar.gz -o nats-server.tar.gz
  tar -xzf nats-server.tar.gz
  cp nats-server-v2.10.0-darwin-arm64/nats-server /usr/local/bin/
  ```

  ```bash macOS (Intel) theme={null}
  curl -L https://github.com/nats-io/nats-server/releases/latest/download/nats-server-v2.10.0-darwin-amd64.tar.gz -o nats-server.tar.gz
  tar -xzf nats-server.tar.gz
  cp nats-server-v2.10.0-darwin-amd64/nats-server /usr/local/bin/
  ```

  ```powershell Windows theme={null}
  Invoke-WebRequest -Uri "https://github.com/nats-io/nats-server/releases/latest/download/nats-server-v2.10.0-windows-amd64.zip" -OutFile "nats-server.zip"
  Expand-Archive -Path "nats-server.zip" -DestinationPath "."
  Move-Item nats-server-v2.10.0-windows-amd64\nats-server.exe C:\Windows\System32\
  ```
</CodeGroup>

<Note>
  Replace `v2.10.0` with the actual latest version number from the [releases page](https://github.com/nats-io/nats-server/releases).
</Note>

## Platform-Specific Installation

### Linux

#### Quick Installation

```bash theme={null}
# Download and install to /usr/local/bin
curl -sf https://binaries.nats.dev/nats-io/nats-server@latest | sh
```

#### Manual Installation

```bash theme={null}
# Download the binary
wget https://github.com/nats-io/nats-server/releases/latest/download/nats-server-v2.10.0-linux-amd64.tar.gz

# Extract
tar -xzf nats-server-v2.10.0-linux-amd64.tar.gz

# Move to PATH
sudo mv nats-server-v2.10.0-linux-amd64/nats-server /usr/local/bin/

# Make executable
sudo chmod +x /usr/local/bin/nats-server

# Verify installation
nats-server --version
```

#### Package Managers

<CodeGroup>
  ```bash Homebrew (Linux) theme={null}
  brew install nats-server
  ```

  ```bash Snapcraft theme={null}
  sudo snap install nats-server
  ```
</CodeGroup>

### macOS

#### Homebrew (Recommended)

```bash theme={null}
brew install nats-server
```

#### Manual Installation

```bash theme={null}
# Download for your architecture
curl -L https://github.com/nats-io/nats-server/releases/latest/download/nats-server-v2.10.0-darwin-arm64.tar.gz -o nats-server.tar.gz

# Extract
tar -xzf nats-server.tar.gz

# Move to PATH
sudo mv nats-server-v2.10.0-darwin-arm64/nats-server /usr/local/bin/

# Verify installation
nats-server --version
```

### Windows

#### Manual Installation

1. Download the Windows ZIP from [GitHub Releases](https://github.com/nats-io/nats-server/releases)
2. Extract the ZIP file
3. Move `nats-server.exe` to a directory in your PATH (e.g., `C:\Windows\System32`)
4. Verify installation:

```powershell theme={null}
nats-server --version
```

#### Chocolatey

```powershell theme={null}
choco install nats-server
```

#### Scoop

```powershell theme={null}
scoop install nats-server
```

## Running NATS Server

### Basic Usage

Start NATS with default settings:

```bash theme={null}
nats-server
```

The server will:

* Listen on port 4222 for client connections
* Listen on 0.0.0.0 (all interfaces)
* Run in the foreground

### With Configuration File

```bash theme={null}
nats-server -c /path/to/nats-server.conf
```

### Command Line Options

```bash theme={null}
nats-server --port 4222 --http_port 8222 --log /var/log/nats.log
```

Common options:

* `-p, --port` - Client connection port (default: 4222)
* `-a, --addr` - Network address to bind (default: 0.0.0.0)
* `-m, --http_port` - HTTP monitoring port
* `-c, --config` - Configuration file path
* `-l, --log` - Log file path
* `-D, --debug` - Enable debug logging
* `-V, --trace` - Enable trace logging
* `-js` - Enable JetStream
* `--sd` - JetStream storage directory

### Enable JetStream

```bash theme={null}
nats-server -js -sd /data/nats
```

## Running as a Service

### systemd (Linux)

Create a systemd service file:

```ini /etc/systemd/system/nats-server.service theme={null}
[Unit]
Description=NATS Server
After=network.target

[Service]
Type=simple
User=nats
Group=nats
ExecStart=/usr/local/bin/nats-server -c /etc/nats/nats-server.conf
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536

# Security settings
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/lib/nats /var/log/nats
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
```

Set up the service:

```bash theme={null}
# Create nats user
sudo useradd -r -s /bin/false nats

# Create necessary directories
sudo mkdir -p /etc/nats /var/lib/nats /var/log/nats
sudo chown nats:nats /var/lib/nats /var/log/nats

# Copy configuration
sudo cp nats-server.conf /etc/nats/

# Reload systemd
sudo systemctl daemon-reload

# Enable and start service
sudo systemctl enable nats-server
sudo systemctl start nats-server

# Check status
sudo systemctl status nats-server
```

### launchd (macOS)

Create a launch agent:

```xml ~/Library/LaunchAgents/io.nats.nats-server.plist theme={null}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>io.nats.nats-server</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/nats-server</string>
        <string>-c</string>
        <string>/usr/local/etc/nats-server.conf</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/nats-server.log</string>
    <key>StandardOutPath</key>
    <string>/usr/local/var/log/nats-server.log</string>
</dict>
</plist>
```

Load the service:

```bash theme={null}
launchctl load ~/Library/LaunchAgents/io.nats.nats-server.plist
```

### Windows Service

Use [NSSM](https://nssm.cc/) (Non-Sucking Service Manager):

```powershell theme={null}
# Install NSSM
choco install nssm

# Install NATS as a service
nssm install NATS "C:\Program Files\nats-server\nats-server.exe" "-c" "C:\Program Files\nats-server\nats-server.conf"

# Start the service
nssm start NATS

# Check status
nssm status NATS
```

## Updating and Upgrading

### Manual Update

1. Download the new version
2. Stop the running server
3. Replace the binary
4. Restart the server

```bash theme={null}
# Stop the service
sudo systemctl stop nats-server

# Download new version
wget https://github.com/nats-io/nats-server/releases/download/v2.11.0/nats-server-v2.11.0-linux-amd64.tar.gz

# Extract and replace
tar -xzf nats-server-v2.11.0-linux-amd64.tar.gz
sudo mv nats-server-v2.11.0-linux-amd64/nats-server /usr/local/bin/

# Start the service
sudo systemctl start nats-server

# Verify version
nats-server --version
```

### Package Manager Updates

<CodeGroup>
  ```bash Homebrew theme={null}
  brew upgrade nats-server
  ```

  ```bash Chocolatey theme={null}
  choco upgrade nats-server
  ```

  ```bash Snap theme={null}
  sudo snap refresh nats-server
  ```
</CodeGroup>

### Zero-Downtime Updates

For clustered deployments, update nodes one at a time:

```bash theme={null}
# Update each node sequentially
for node in node1 node2 node3; do
  ssh $node 'systemctl stop nats-server && \
             wget ... && \
             systemctl start nats-server'
  sleep 30  # Allow cluster to stabilize
done
```

## Verifying Installation

### Check Version

```bash theme={null}
nats-server --version
```

### Test Configuration

```bash theme={null}
nats-server -c /path/to/nats-server.conf -t
```

The `-t` flag validates configuration without starting the server.

### Test Connection

```bash theme={null}
# Start server
nats-server &

# Test with nats CLI (if installed)
nats pub test "Hello World"

# Or use telnet
telnet localhost 4222
```

## Security Considerations

<Warning>
  Always run NATS Server as a non-root user in production environments.
</Warning>

### File Permissions

```bash theme={null}
# Binary permissions
sudo chmod 755 /usr/local/bin/nats-server

# Configuration file (may contain secrets)
sudo chmod 600 /etc/nats/nats-server.conf
sudo chown nats:nats /etc/nats/nats-server.conf
```

### Firewall Rules

Allow necessary ports:

```bash theme={null}
# UFW (Ubuntu)
sudo ufw allow 4222/tcp  # Client connections
sudo ufw allow 6222/tcp  # Cluster routes
sudo ufw allow 8222/tcp  # Monitoring (restrict to internal network)

# firewalld (CentOS/RHEL)
sudo firewall-cmd --permanent --add-port=4222/tcp
sudo firewall-cmd --permanent --add-port=6222/tcp
sudo firewall-cmd --permanent --add-port=8222/tcp
sudo firewall-cmd --reload
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Use Configuration Files" icon="file-code">
    Store configuration in files rather than using command-line flags for better maintainability.
  </Card>

  <Card title="Run as Service" icon="server">
    Use systemd, launchd, or Windows services for automatic restarts and proper lifecycle management.
  </Card>

  <Card title="Regular Updates" icon="arrow-up">
    Keep NATS Server updated to benefit from security patches and new features.
  </Card>

  <Card title="Monitor Logs" icon="file-lines">
    Configure proper logging and monitor logs for errors and performance issues.
  </Card>
</CardGroup>

## Troubleshooting

### Binary Not Found

Ensure the binary is in your PATH:

```bash theme={null}
which nats-server
# If not found, add to PATH:
export PATH=$PATH:/usr/local/bin
```

### Permission Denied

```bash theme={null}
chmod +x /usr/local/bin/nats-server
```

### Port Already in Use

Check what's using port 4222:

```bash theme={null}
sudo lsof -i :4222
# or
sudo netstat -tulpn | grep 4222
```

### Service Won't Start

Check service logs:

```bash theme={null}
# systemd
sudo journalctl -u nats-server -f

# macOS
log show --predicate 'process == "nats-server"' --last 1h
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Configuration" icon="gear" href="./configuration">
    Learn about configuration options and best practices
  </Card>

  <Card title="Docker Deployment" icon="docker" href="/deployment/docker">
    Explore containerized deployment options
  </Card>
</CardGroup>
