Documentation

Install and run GainDrive.

Requirements

GainDrive Server is a single statically linked executable with no runtime dependencies. Binaries are provided for arm64 and x86_64 Linux.

  • A machine that can reach your music files — a Raspberry Pi, a NAS or a small VPS is plenty.
  • Disk space for two SQLite databases; these stay small relative to the music itself.
  • ffmpeg on PATH, only if you want on-the-fly transcoding.

Install

Linux binary

Download the release for your architecture, make it executable, and move it somewhere on your PATH.

$ curl -LO https://github.com/kpeeters/gaindrive/releases/latest/download/gaindrive-linux-x86_64
$ chmod +x gaindrive-linux-x86_64
$ sudo mv gaindrive-linux-x86_64 /usr/local/bin/gaindrive

Build from source

You need a C++ compiler with C++20 support and CMake.

$ git clone https://github.com/kpeeters/gaindrive.git
$ cd gaindrive
$ cmake -B build -DCMAKE_BUILD_TYPE=Release
$ cmake --build build -j

First run

Point GainDrive at your music folder and start it. On the first start it creates both databases and begins an initial scan.

$ gaindrive --music ~/Music --port 4040

  ♪ GainDrive  ·  listening on :4040
  ✓ scanned 1,284 albums · 18,902 tracks
  ✓ web player ready → http://localhost:4040

Open http://localhost:4040 in a browser and create the first account; it becomes the administrator. Further accounts are added from the admin panel in the web player.

info
The initial scan runs in the background. Large collections keep populating while you browse, and metadata lookups continue after the file scan finishes.

Configuring your library

GainDrive reads metadata from ID3 tags where they exist, and falls back to the folder structure where they do not. Either way it presents one unified library to every client.

A conventional layout gives the best results, and multi-disc sets are picked up automatically:

Music/
├── Artist Name/
│   ├── 1994 — Album Title/
│   │   ├── 01 First Track.flac
│   │   └── cover.jpg
│   └── 1998 — Box Set/
│       ├── Disc 1/
│       └── Disc 2/

Folders are watched with inotify, so added, moved and retagged files are reflected without a manual rescan. Artist and album metadata and artwork missing from your files are fetched from MusicBrainz and other sources.

Running as a service

To keep GainDrive running across reboots, install it as a systemd unit at /etc/systemd/system/gaindrive.service.

[Unit]
Description=GainDrive music server
After=network.target

[Service]
User=music
ExecStart=/usr/local/bin/gaindrive --music /srv/music --port 4040
Restart=on-failure

[Install]
WantedBy=multi-user.target
$ sudo systemctl enable --now gaindrive
$ systemctl status gaindrive

Reverse proxy & HTTPS

Put GainDrive behind nginx or Caddy if you want it reachable from outside your network with a certificate.

server {
    server_name music.example.com;

    location / {
        proxy_pass http://127.0.0.1:4040;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
cast
Casting from the server needs the Chromecast device to be able to reach the server directly on your local network. If your server is only reachable over a VPN, use the Android app's bridge mode instead.

Transcoding

When a client asks for a format or bitrate your files are not already in, GainDrive transcodes on the fly using ffmpeg. Enable a cache so a given transcode is only produced once.

$ gaindrive --music /srv/music \
           --transcode-cache /var/cache/gaindrive

Without ffmpeg on PATH, GainDrive streams original files only; everything else keeps working.

Android app

Install the APK from the releases page. You will need to allow installation from unknown sources the first time.

  1. Add a server. Open the app, tap Add server, and enter your server URL (for example https://music.example.com) with your username and password.
  2. Add more servers if you want. Any OpenSubsonic-compatible server can be added alongside your own; their artist and album lists are merged into one browsable library.
  3. Cache for offline. Long-press an album or playlist and choose Download to keep it on the device; cached music plays with no connection to the server.
  4. Cast. Tap the cast icon to send playback to any Chromecast on the network. The app uses its own Chromecast implementation, so it works on de-Googled phones, and it can bridge playback when the server is behind a VPN but the Chromecast is not.

iOS app

Other Subsonic clients

GainDrive speaks the OpenSubsonic API, so any compatible client on iOS, Android or desktop works. Point the client at your server URL and sign in with a GainDrive account. Each user gets their own playlists and listening history.

Troubleshooting

The library is empty after starting

Check that the user running GainDrive can read the music directory, and that --music points at the folder containing your artist folders rather than a parent of it.

New files are not appearing

Filesystem watching relies on inotify, which does not work over most network mounts. On an NFS or SMB share, run a periodic rescan instead.

Albums are split or tracks are out of order

This is almost always inconsistent tagging — usually the album artist differing between tracks. Fix the tags and the watcher will regroup the album on its own.

Playback fails on one client but not another

That client is likely requesting a format your files are not in. Install ffmpeg so transcoding can take over.

Still stuck? Open an issue on GitHub.