Complete installation instructions for setting up your GRAIN relay server.
- Overview
- System Requirements
- Method 1: Pre-built Binaries (Recommended)
- Method 2: Building from Source
- Method 3: Docker Deployment
- Data Directory & Storage
- First Run Setup
- Configuration
- Service Installation
- Verification
- Troubleshooting
- Next Steps
GRAIN is a zero-dependency, single-binary Nostr relay and client library. Starting with v0.5.0, it no longer requires an external database like MongoDB. All storage is handled by an embedded, high-performance engine (nostrdb).
GRAIN can be installed in three ways:
- Pre-built binaries - Download and run (recommended for most users)
- Build from source - Compile yourself for custom builds or unsupported platforms
- Docker containers - Containerized deployment for modern infrastructure
| Platform | Architecture | Pre-built Binary | Source Build | Docker |
|---|---|---|---|---|
| Linux | x86_64 | ✅ | ✅ | ✅ |
| Linux | ARM64 | ✅ | ✅ | ✅ |
| macOS | x86_64 | ✅ | ✅ | ✅ |
| macOS | ARM64 (M1/M2) | ✅ | ✅ | ✅ |
| Windows | x86_64 | ✅ | ✅ | ✅ |
The fastest way to get GRAIN running is using pre-built binaries.
-
Visit the releases page: https://github.com/0ceanslim/grain/releases
-
Download for your platform: Look for the archive corresponding to your OS and architecture.
Linux/macOS:
# Extract the archive
tar -xzf grain-*.tar.gz
# Make executable
chmod +x grain
# Move to a directory in your PATH (optional)
sudo mv grain /usr/local/bin/Windows:
- Extract the
.ziparchive to a folder of your choice. - You will see
grain.exe. This is the only file you need.
grain --versionExpected output:
GRAIN v0.5.0
Go Relay Architecture for Implementing Nostr
Building from source requires a C compiler and Go 1.23+ due to the embedded nostrdb (C library).
- Go 1.23+ - Download Go
- C Compiler (gcc or clang)
- Make (for using build scripts)
# Clone repository including submodules
git clone --recursive https://github.com/0ceanslim/grain.git
cd grain
# Build binary
go build -o grain .On Windows, it is recommended to use MSYS2 with the mingw-w64-x86_64-gcc package for the C components.
For containerized deployment, please refer to the Docker Documentation.
Since v0.5.0, the Docker image is significantly smaller as it no longer bundles MongoDB.
GRAIN stores its database, logs, and configuration files in a platform-specific data directory.
| OS | Default Path |
|---|---|
| Linux | ~/.grain/ |
| macOS | ~/Library/Application Support/grain/ |
| Windows | %APPDATA%\grain\ |
You can override the default location in two ways:
- CLI Flag:
grain --data-dir /path/to/custom/dir - Environment Variable:
export GRAIN_DATA_DIR=/path/to/custom/dir
Inside the data directory, GRAIN maintains:
data/- The nostrdb LMDB database files.config.yml- Main server configuration.whitelist.yml/blacklist.yml- Policy files.relay_metadata.json- NIP-11 information.logs/- Structured application logs.
Simply run the binary. On the first run, GRAIN will detect that no configuration exists and generate default files in your platform's data directory.
./grainIf you are migrating from an older version of GRAIN that used MongoDB:
- Export your MongoDB events to a JSONL file.
- Import them into the new engine:
./grain --import events_export.jsonl
GRAIN uses hot-reloading for all configuration files. You can edit them while the server is running, and changes will be applied instantly.
config.yml: Database paths, network settings, and rate limits.whitelist.yml: Allowed pubkeys and domains.blacklist.yml: Banned content and users.relay_metadata.json: Public info served via NIP-11.
See the Configuration Guide for full details.
Create /etc/systemd/system/grain.service:
[Unit]
Description=GRAIN Nostr Relay
After=network.target
[Service]
Type=simple
User=grain
Group=grain
ExecStart=/usr/local/bin/grain
Restart=always
RestartSec=5
# Security settings
NoNewPrivileges=true
ProtectSystem=full
[Install]
WantedBy=multi-user.targetcurl -I http://localhost:8181
# Should return 200 OKcurl -H "Accept: application/nostr+json" http://localhost:8181Use websocat to test the relay:
echo '["REQ","test",{"kinds":[1],"limit":1}]' | websocat ws://localhost:8181If building from source fails, ensure you have a working C compiler and that git submodules were properly initialized (git submodule update --init --recursive).
Ensure the user running GRAIN has write access to the data directory (e.g., ~/.grain).
If you see "MDB_MAP_FULL" in the logs, increase the database.map_size_mb in config.yml. The default is 4096 (4GB).
- Configure your relay: Edit
config.ymlandrelay_metadata.json. - Set up NIP-05: Whitelist your pubkey using domain-based verification.
- Monitor: Check the web dashboard at
http://localhost:8181.
Installation Complete! 🌾