# Install via Cargo

Installing socktop via Cargo gives you access to the latest version and works on any Linux distribution with Rust installed.

## Prerequisites

Before installing via Cargo, ensure you have:

- **Rust 1.70 or newer** - Install via [rustup](https://rustup.rs/)
- **Build dependencies** - See [Prerequisites](./prerequisites.md) for details
- **GPU support libraries** - Required on all systems:
  ```bash
  sudo apt install libdrm-dev libdrm-amdgpu1
  ```

## Installation

### Installing the TUI Client

```bash
cargo install socktop
```

This will download, compile, and install the `socktop` binary to `~/.cargo/bin/`. Make sure this directory is in your `PATH`.

### Installing the Agent

```bash
cargo install socktop-agent
```

This installs the `socktop_agent` binary to `~/.cargo/bin/`.

### Installing Both (Recommended)

```bash
cargo install socktop socktop-agent
```

## Verify Installation

Check that the binaries are installed correctly:

```bash
# Check socktop client
socktop --version

# Check socktop agent
socktop_agent --version
```

You should see output like:
```
socktop 1.50.2
```

## First Run

### Start the Agent

Start the agent in a separate terminal or background process:

```bash
# Run in foreground (for testing)
socktop_agent

# Run in background
socktop_agent &

# Or with custom options
socktop_agent --port 3000 --host 0.0.0.0
```

### Connect with the Client

In another terminal, connect to the agent:

```bash
# Monitor local system
socktop

# Or explicitly specify the WebSocket URL
socktop ws://localhost:3000
```

## Configuration

### Agent Configuration

The agent accepts the following command-line arguments:

```bash
socktop_agent --help
```

Common options:
- `--port <PORT>` - Port to listen on (default: 3000)
- `--host <HOST>` - Host/IP to bind to (default: 0.0.0.0)
- `--token <TOKEN>` - Authentication token (optional)
- `--tls-cert <CERT>` - TLS certificate path (optional)
- `--tls-key <KEY>` - TLS private key path (optional)

Example with custom configuration:
```bash
socktop_agent --port 8080 --token mySecretToken123
```

### Client Configuration

The client can connect using various methods:

```bash
# Local connection
socktop

# Remote connection
socktop ws://192.168.1.100:3000

# Secure connection with TLS
socktop wss://secure-host:3000

# Using a connection profile
socktop -P my-server
```

See [Configuration](../usage/configuration.md) for details on setting up profiles.

## System-wide agent (Linux)

```bash
# If you installed with cargo, binaries are in ~/.cargo/bin
sudo install -o root -g root -m 0755 "$HOME/.cargo/bin/socktop_agent" /usr/local/bin/socktop_agent

# Install and enable the systemd service (example unit in docs/)
sudo install -o root -g root -m 0644 docs/socktop-agent.service /etc/systemd/system/socktop-agent.service
sudo systemctl daemon-reload
sudo systemctl enable --now socktop-agent
```
