In short
To set up Lavalink, install Java 17 or newer on your server, create an application.yml next to Lavalink.jar with a port and password, add the youtube-plugin for YouTube support, and run Lavalink 24/7 as a systemd service. Then point a client library in your bot, such as Shoukaku or Wavelink, at 127.0.0.1:2333 with that password. For small bots, 3 GB of RAM is usually enough.
In this guide
- What is Lavalink, and why is it a separate part of a music bot?
- Requirements
- Step 1: Install Java
- Step 2: Create the application.yml file
- Step 3: Test Lavalink and run it 24/7 with systemd
- Step 4: Connect your bot to Lavalink
- RAM and CPU requirements by bot size
- Common Lavalink errors
- Next step: pick the right server for your music bot
Setting up Lavalink takes three steps: install Java 17 or newer on your server, create an application.yml next to Lavalink.jar to set the port and password, then give that address and password to the Lavalink client in your bot. This guide walks you through running Lavalink 24/7 on a Linux server, adding the YouTube plugin, connecting discord.js and discord.py bots, and sizing RAM and CPU for your bot's load.
What is Lavalink, and why is it a separate part of a music bot?
Lavalink is an open-source audio server written in Java. Your music bot doesn't download or encode songs itself. It sends Lavalink a command like "play this track in this server." Lavalink resolves the source (YouTube, SoundCloud, Twitch, an HTTP stream, and so on), converts the audio to the Opus format Discord expects, and streams it straight to the voice channel.
This split has two benefits:
- Your bot process stays lightweight: Audio processing doesn't block your Node.js or Python process, so commands respond without lag.
- It scales: As your bot grows, you can move Lavalink to its own server or run multiple Lavalink nodes.
The trade-off: Lavalink runs on the Java Virtual Machine (JVM), so it uses much more RAM than the bot itself. That's why music bots on free, low-resource hosts tend to disconnect and stutter.
Requirements
- A Linux server with root or sudo access (this guide uses Ubuntu/Debian commands).
- Java 17 or newer. Lavalink v4 requires at least Java 17; the long-term support (LTS) releases 17 or 21 are recommended.
- If the bot and Lavalink run on the same machine, at least 2 GB of RAM, or 3–4 GB for comfortable headroom.
Built for exactly this job, the OB-DISCORD-2 Discord Bot VDS plan (4 vCPU, 3 GB RAM) with KVM virtualization and root access is a good starting point for running your bot and Lavalink on the same server.
Step 1: Install Java
Connect to your server over SSH, update the package list, and install the headless Java runtime:
sudo apt update
sudo apt install -y openjdk-17-jre-headless
java -versionThe java -version output should show version 17 or higher. If your distribution's repositories include Java 21, you can use the openjdk-21-jre-headless package instead.
For security, run Lavalink as a dedicated user, not as root:
sudo useradd -r -m -d /opt/lavalink -s /usr/sbin/nologin lavalink
cd /opt/lavalink
sudo -u lavalink wget https://github.com/lavalink-devs/Lavalink/releases/latest/download/Lavalink.jarStep 2: Create the application.yml file
Lavalink reads its settings from the application.yml file in its working directory. Create /opt/lavalink/application.yml and paste in this basic configuration:
server:
port: 2333
address: 127.0.0.1
lavalink:
plugins:
- dependency: "dev.lavalink.youtube:youtube-plugin:SURUM"
snapshot: false
server:
password: "buraya-uzun-ve-rastgele-bir-sifre"
sources:
youtube: false
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
http: true
local: false
bufferDurationMs: 400
frameBufferDurationMs: 5000
youtubePlaylistLoadLimit: 6
playerUpdateInterval: 5
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
plugins:
youtube:
enabled: true
allowSearch: true
allowDirectVideoIds: true
allowDirectPlaylistIds: true
logging:
level:
root: INFO
lavalink: INFOWhat the key lines do:
server.port: 2333: The port Lavalink listens on. 2333 is the de facto default in the Lavalink ecosystem.server.address: 127.0.0.1: Exposes Lavalink only to a bot on the same server. If your bot runs on another machine, set it to0.0.0.0and open the port in your firewall to the bot's IP only.password: The password your bot sends when it connects. Replace the placeholder with a long, random password, and never use the default password from sample files.youtube: false+ the YouTube plugin: The built-in YouTube source is deprecated in Lavalink v4; YouTube support now comes from the separate youtube-plugin. ReplaceSURUM(Turkish for "version") with the current version number from the plugin's GitHub releases page. Lavalink downloads the plugin automatically on first startup.
Step 3: Test Lavalink and run it 24/7 with systemd
First, start it manually and check for errors:
cd /opt/lavalink
sudo -u lavalink java -Xmx1G -jar Lavalink.jarWhen the log shows a line like Lavalink is ready to accept connections, the server is ready. Stop it with Ctrl+C and set up a persistent service. Create /etc/systemd/system/lavalink.service:
[Unit]
Description=Lavalink ses sunucusu
After=network-online.target
Wants=network-online.target
[Service]
User=lavalink
WorkingDirectory=/opt/lavalink
ExecStart=/usr/bin/java -Xms256M -Xmx1G -jar /opt/lavalink/Lavalink.jar
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now lavalink
sudo journalctl -u lavalink -fThe -Xmx value is the maximum memory the JVM can use. Don't set it to your server's total RAM; leave room for the operating system and your bot.
Step 4: Connect your bot to Lavalink
Your bot needs a client library to talk to Lavalink. Whichever library you choose, you'll provide three things: the address (127.0.0.1:2333), the password, and whether to use a secure connection (false on the same server). Also make sure your bot has the GuildVoiceStates intent enabled; without it, voice channel data can't reach Lavalink.
discord.js (with Shoukaku)
const { Client, GatewayIntentBits } = require('discord.js');
const { Shoukaku, Connectors } = require('shoukaku');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates]
});
const nodes = [{
name: 'ana-node',
url: '127.0.0.1:2333',
auth: process.env.LAVALINK_PASSWORD
}];
const shoukaku = new Shoukaku(new Connectors.DiscordJS(client), nodes);
shoukaku.on('error', (name, error) => console.error(`Lavalink ${name}:`, error));
client.login(process.env.DISCORD_TOKEN);discord.py (with Wavelink)
import os
import discord
import wavelink
from discord.ext import commands
class MuzikBotu(commands.Bot):
async def setup_hook(self):
node = wavelink.Node(uri="http://127.0.0.1:2333",
password=os.environ["LAVALINK_PASSWORD"])
await wavelink.Pool.connect(nodes=[node], client=self)
intents = discord.Intents.default()
intents.voice_states = True
bot = MuzikBotu(command_prefix="!", intents=intents)
bot.run(os.environ["DISCORD_TOKEN"])Don't hard-code the password or token. Read them from environment variables or a .env file instead. Our Discord bot token security guide explains why the token matters so much.
RAM and CPU requirements by bot size
Lavalink's resource usage depends not on how many servers your bot is in, but on how many players are active at the same time. If your bot is in 500 servers but only 5 people are listening at once, the load is light. Each active player decodes audio and re-encodes it to Opus, so the load builds up on the CPU. Use the table below as a starting point, and find your exact numbers by monitoring your own daily usage.
| Bot size | Concurrent players (estimated) | Lavalink -Xmx | Recommended server |
|---|---|---|---|
| Your own community, 1–20 servers | 1–10 | 512M–1G | 3 GB RAM, bot + Lavalink on the same machine |
| Mid-size, a few hundred servers | 10–50 | 1G–2G | 4 GB RAM, multi-core |
| Large public bot | 50+ | 2G and up | Dedicated VDS for Lavalink or multiple nodes |
A practical rule: leave at least 1 GB for the bot process and the operating system, and at least 512 MB for Lavalink. Choppy or "robotic" audio usually means the CPU can't keep up, while Lavalink restarting usually means the -Xmx value is too low.
As your concurrent player count grows, moving to the OB-DISCORD-3 plan with 4 vCPU and 4 GB RAM lets you give Lavalink a larger memory allocation.
Common Lavalink errors
- Bot can't connect, "401" or authorization error: The password in your bot doesn't exactly match the one in
application.yml. - "Connection refused": Lavalink isn't running, or
addressis 127.0.0.1 while the bot is connecting from another machine. Check withjournalctl -u lavalink. - YouTube tracks won't load: The YouTube plugin may be outdated. YouTube changes things often, so keep the plugin up to date.
- Bot joins the voice channel but there's no sound: Usually the
GuildVoiceStatesintent is missing, or the bot lacks the "Speak" permission in the channel. - Lavalink shuts down every few hours: The server may be running out of memory. Run
dmesg | grep -i oomto see whether the kernel killed the process.
If your bot goes fully offline from time to time, the cause may be outside Lavalink; work through the checklist in our Discord bot keeps going offline guide.
Next step: pick the right server for your music bot
Because of the JVM and audio encoding, Lavalink needs more resources than a typical moderation bot, which is why music bots are hard to run reliably on a home PC or free platforms. OyunBulut's Discord Bot VDS plans in Istanbul come with KVM virtualization, root access, and multi-layer DDoS protection, so you can run the commands above exactly as written. Start with OB-DISCORD-2 for small to mid-size music bots, and move to OB-DISCORD-3 as your concurrent listener count grows. If you're moving your bot to a server for the first time, the guide to deploying a discord.js bot on a VDS and running it 24/7 with PM2 will help too.
Frequently asked questions
Which Java version does Lavalink need?
Lavalink v4 requires at least Java 17. Java 17 or Java 21 is recommended because both are long-term support (LTS) releases.
Why won't YouTube play with Lavalink?
The built-in YouTube source is deprecated in Lavalink v4. Disable the youtube source in application.yml, add the youtube-plugin, and keep the plugin up to date.
How much RAM does Lavalink use?
It depends on how many players are active at once. For small community bots, an -Xmx value between 512 MB and 1 GB is usually enough. Busy bots need 2 GB or more.
Can the bot and Lavalink run on the same server?
Yes. For small and mid-size bots, it's the most practical setup. In that case, the safest option is to have Lavalink listen on 127.0.0.1 and not expose the port to the internet.
What is Lavalink's default port?
Lavalink uses port 2333 by default. You can change it with the server.port line in application.yml; update your bot's connection settings to match the new port.