Running Lavalink on a Raspberry Pi Zero 2 W

In this post you'll get a tutorial on how to run Lavalink on a tiny Raspberry Pi Zero 2 W and learn the hitches along the way.

Running Lavalink on a Raspberry Pi Zero 2 W

If you're here, you probably know what Lavalink is, but to quote the project readme:

A standalone audio sending node based on Lavaplayer and JDA-Audio. Allows for sending audio without it ever reaching any of your shards.

Or for what it means to me: How a Discord bot can have audio playing functionality - particularly YouTube.

GitHub - freyacodes/Lavalink: Standalone audio sending node based on Lavaplayer.
Standalone audio sending node based on Lavaplayer. - GitHub - freyacodes/Lavalink: Standalone audio sending node based on Lavaplayer.

Lavalink is written in Java and has many libraries in your favourite language to interact with it. In the .NET space, I personally like to use Victoria:

GitHub - Yucked/Victoria: ๐ŸŒ‹ - Lavalink wrapper for Discord.NET. Provides more options and performs better than all .NET Lavalink libraries combined.
๐ŸŒ‹ - Lavalink wrapper for Discord.NET. Provides more options and performs better than all .NET Lavalink libraries combined. - GitHub - Yucked/Victoria: ๐ŸŒ‹ - Lavalink wrapper for Discord.NET. Provide...

In this post we'll be looking at how to get Lavalink running on a Raspberry Pi Zero 2 W by:

  1. Installing Java
  2. Running Lavalink

Installing Java

Lavalink has issues with a couple of Java versions and as such I opted to install Java 16 which seems to work. Follow the post below for installation instructions:

Installing Java 16 on a Raspberry Pi Zero 2 W
Installing Java 16 on a Raspberry Pi Zero 2 W is a bit of a pain and this tutorial will guide you through it.
โ—
At the time of writing this there is an issue with Lavalink.jar and the Zero 2 W that prevents playing of some audio file types. Windows works fine.

Issue resolution a little lower.

We can grab Lavalink from the releases page on the GitHub repo. However, in order to run Lavalink you also need to put an application.yaml file in the same directory as Lavalink.jar. Thankfully, there is a good default example hosted in the repo too.

From here head to where you put the two files mentioned just above and we can run the following command (might take a little to get going):

java -jar Lavalink.jar

Which should result in:

Lavalink running.

As hinted to earlier, for some reason the .jar file does not properly work specifically on the Zero 2 W. We can fix this by using a custom patched .jar:

GitHub - Cog-Creators/Lavalink-Jars: Repository for hosting Lavalink Jarfiles for Red-DiscordBot.
Repository for hosting Lavalink Jarfiles for Red-DiscordBot. - GitHub - Cog-Creators/Lavalink-Jars: Repository for hosting Lavalink Jarfiles for Red-DiscordBot.

This repo seems to take the Lavalink repository and create custom patched versions. I originally stumbled upon it with this GitHub issue comment:

Add support for musl ยท Issue #537 ยท sedmelluq/lavaplayer
core dump: dump.txt Steps to reproduce: (with red-discordbot) Play something Change volume mid playback Crash Related: Cog-Creators/Red-DiscordBot/issues/4520 #177

Essentially using the custom patched .jar works just the same as the original. For my purposes I use the original when using Windows and the patched version when running on the Pi. Remember you'll need the application.yaml still.

To Conclude

With this you can now successfully run Lavalink on your little Pi Zero 2 W (or Windows for development like I did). Happy coding!