This README guide provides a comprehensive tutorial on what Lavalink is, how to set up your own Lavalink server, and how to keep it running 24/7 from different environments such as your PC, VPS, and even your phone using Termux.
Lavalink is a high-performance audio streaming server that is primarily used by Discord bots for managing audio playback. It offloads audio decoding and streaming from your bot to a separate server, providing enhanced performance, scalability, and reliability for music bots.
Lavalink is based on the Lavaplayer library, which enables efficient audio streaming from sources such as YouTube, SoundCloud, and more. It communicates with your Discord bot through a specific protocol (using WebSocket or HTTP), enabling it to stream audio without putting excessive load on the bot itself.
- High-performance streaming with low latency.
- Supports a variety of audio formats (MP3, OGG, etc.).
- Can stream audio from platforms like YouTube and SoundCloud.
- Offloads audio processing from your Discord bot, reducing resource consumption.
- Java 11 or higher.
- Git (if you wish to clone the Lavalink repository).
- Redis (optional, for caching).
Lavalink is built with Java, so you need to have Java 11 or later installed on your system.
For Linux (Ubuntu/Debian):
sudo apt update
sudo apt install openjdk-11-jdk
For Windows or macOS, download Java from the AdoptOpenJDK website and install it.
To get the Lavalink server, you can either clone it directly from GitHub or download the precompiled Lavalink.jar
file.
To clone the repository:
git clone https://github.com/freyacodes/Lavalink.git
cd Lavalink
If you want the precompiled JAR, download it from the releases page.
If you cloned the repository and want to build Lavalink, run the following command:
./mvnw clean install
This will compile the Lavalink server and prepare it for use.
Lavalink uses a application.yml
file for configuration. Edit this file to set up your Lavalink server:
server:
port: 2333 # Default port for Lavalink
password: "yoursecretpassword" # Set a password to connect with your bot
redis:
host: localhost # Optional, for Redis caching (can leave out if not using Redis)
port: 6379
ytdlOptions:
youtube_dl:
max-downloads: 5 # Max YouTube downloads (optional)
Make sure to replace "yoursecretpassword"
with a strong password.
Now, start the Lavalink server by running the following command:
java -jar Lavalink.jar
The server should now be running on port 2333
(or the port you configured).
You can keep your Lavalink server running 24/7 from PC, VPS, and even from your phone using Termux.
If you are running Lavalink from your PC, use tools like screen or tmux to keep it running even if the terminal is closed.
-
Install
screen
(if not already installed):sudo apt install screen
-
Start a new screen session:
screen -S lavalink
-
Run the Lavalink server:
java -jar Lavalink.jar
-
Detach from the screen session (without stopping the server): Press
Ctrl + A
, then pressD
. -
To reattach to the session:
screen -r lavalink
-
Install
tmux
:sudo apt install tmux
-
Start a new tmux session:
tmux new -s lavalink
-
Run Lavalink:
java -jar Lavalink.jar
-
Detach from the session: Press
Ctrl + B
, then pressD
. -
To reattach to the tmux session:
tmux attach -t lavalink
To keep Lavalink running 24/7 on a VPS, you can use systemd
, which will automatically restart Lavalink if it crashes and ensure it starts on reboot.
-
Create a
lavalink.service
file in/etc/systemd/system/
:sudo nano /etc/systemd/system/lavalink.service
-
Add the following content:
[Unit] Description=Lavalink Server After=network.target [Service] User=your_username WorkingDirectory=/path/to/lavalink ExecStart=/usr/bin/java -jar /path/to/Lavalink.jar Restart=always RestartSec=10 LimitNOFILE=4096 [Install] WantedBy=multi-user.target
-
Reload the systemd configuration:
sudo systemctl daemon-reload
-
Start the Lavalink service:
sudo systemctl start lavalink
-
Enable Lavalink to start on boot:
sudo systemctl enable lavalink
-
Check the status of Lavalink:
sudo systemctl status lavalink
You can also run Lavalink 24/7 on your Android phone using Termux, which provides a Linux-like environment.
-
Install Termux from the Google Play Store or F-Droid.
-
Open Termux and install required packages:
pkg update pkg install openjdk-11 pkg install git
-
Clone the Lavalink repository or upload the precompiled
Lavalink.jar
:git clone https://github.com/freyacodes/Lavalink.git cd Lavalink
-
Run Lavalink in Termux:
java -jar Lavalink.jar
To keep Lavalink running in the background, use screen or tmux as described above.
By following this guide, you can create your own Lavalink server and run it 24/7 from various environments like your PC, VPS, or even your Android phone using Termux. Whether you want to deploy it on a powerful VPS for scalability or keep it running on a mobile device, this setup ensures continuous availability for your Discord bot to handle audio streaming.
Let your music bot play seamlessly across your Discord servers with Lavalink!