Plex Media Server organizes your movies, TV shows, music and photos, fetches artwork and metadata, and streams everything to the Plex apps on phones, smart TVs and browsers. In this tutorial you will install Plex Media Server on a headless Ubuntu 24.04 server, claim it with your Plex account through an SSH tunnel, set up libraries with correct permissions, enable remote access and configure backups of the Plex database.
Prerequisites
To follow this guide you need:
- A server running Ubuntu 24.04 LTS (x86_64), for example a CubePath VPS, with at least 2 GB of RAM. Use 4 GB or more if you expect clients to transcode.
- A non-root user with
sudoprivileges and UFW enabled. - A free Plex account created at
plex.tv. - Enough disk space for your media, ideally on a separate volume from the operating system.
Hardware-accelerated transcoding (Step 6) additionally requires an active Plex Pass subscription and a server with a supported GPU.
Step 1 - Installing Plex Media Server
Plex is proprietary and not part of the Ubuntu archive. Plex publishes a .deb package for Ubuntu on its downloads page.
On your computer, open https://www.plex.tv/media-server-downloads/, choose Plex Media Server, platform Linux, and copy the link for the Ubuntu (16.04+) / Debian (8+) - Intel/AMD 64-bit package. Then, on the server, download it using that link in place of package_url:
cd /tmp
wget -O plexmediaserver.deb "package_url"
Install it with apt, which also resolves any dependencies:
sudo apt install -y ./plexmediaserver.deb
The package creates a plex system user and the plexmediaserver systemd service. Enable it and check that it is running:
sudo systemctl enable --now plexmediaserver
systemctl status plexmediaserver --no-pager
● plexmediaserver.service - Plex Media Server
Loaded: loaded (/usr/lib/systemd/system/plexmediaserver.service; enabled; preset: enabled)
Active: active (running) since ...
Plex listens on port 32400. Confirm it answers locally:
curl -s http://localhost:32400/identity
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="0" claimed="0" machineIdentifier="..." version="1.x.x.xxxx-xxxxxxxxx">
</MediaContainer>
claimed="0" means the server is not yet linked to a Plex account. You will fix that in Step 3.
NoteTo keep Plex updated with
apt upgrade, add the Plex apt repository following the instructions in Plex's support article about Linux updates. Otherwise, repeat this step with a newer package when an update is released.
Step 2 - Preparing the media directories
Plex runs as the plex user, which needs read access to your files. Keep your own user as owner and give the plex group read access:
sudo mkdir -p /srv/media/{movies,shows,music}
sudo chown -R "$USER":plex /srv/media
sudo chmod -R u=rwX,g=rX,o= /srv/media
sudo find /srv/media -type d -exec chmod g+s {} +
The setgid bit on the directories makes new files inherit the plex group. Verify access as the plex user:
sudo -u plex ls /srv/media
movies music shows
Plex matches titles by name, so use its naming scheme when you upload media:
/srv/media/movies/The Dark Knight (2008)/The Dark Knight (2008).mkv
/srv/media/shows/Breaking Bad/Season 01/Breaking Bad - s01e01.mkv
/srv/media/music/Artist Name/Album Name/01 - Track Name.flac
Step 3 - Claiming the server through an SSH tunnel
A new Plex server can only be claimed from the same machine or local network. On a remote server, an SSH tunnel makes your browser look local. Run this on your computer:
ssh -L 32400:localhost:32400 your_user@your_server_ip
Keep the session open and browse to http://localhost:32400/web. Sign in with your Plex account, give the server a name and continue through the setup screens. When asked to add libraries:
- Click Add Library and choose the type (Movies, TV Shows, Music).
- Click Browse for media folder and select the matching directory, such as
/srv/media/movies. - Click Add Library.
Plex starts scanning immediately. Back on the server, confirm the claim:
curl -s http://localhost:32400/identity | grep -o 'claimed="[01]"'
claimed="1"
Step 4 - Enabling remote access
With remote access, Plex apps outside your network connect directly to your server on port 32400. Open the port in UFW:
sudo ufw allow 32400/tcp
In the web app, open Settings > Remote Access (under your server's settings), tick Manually specify public port, enter 32400 and click Enable Remote Access or Retry. After a few seconds the page should show a green Fully accessible outside your network status.
Plex secures remote connections with its own certificates on *.plex.direct hostnames, so you do not need a reverse proxy. Leave Settings > Network > Secure connections set to Preferred or Required.
You can now close the SSH tunnel. From now on, manage the server at https://app.plex.tv with your Plex account.
Step 5 - Tuning transcoding
Transcoding happens when a client cannot play a file's codec, bitrate or subtitles directly. On a CPU-only server it is the main source of load, so the goal is to transcode as little as possible:
- Prefer H.264 video with AAC or AC3 audio in MP4 or MKV containers, which most clients play directly.
- Use text subtitles (SRT) instead of image-based ones (PGS), which force video transcoding when burned in.
Check how many CPU threads you have:
nproc
A single 1080p software transcode typically needs about 2 CPU threads. In Settings > Transcoder, set Maximum simultaneous video transcode to a value your server can sustain (for example 2 on a 4 vCPU VPS), and leave Transcoder quality on Automatic.
Transcoding writes temporary files to the Plex data directory by default. If you have a faster or larger disk, create a directory for it and point Transcoder temporary directory at it:
sudo mkdir -p /srv/plex-transcode
sudo chown plex:plex /srv/plex-transcode
Step 6 - Enabling hardware acceleration (optional)
With Plex Pass and an Intel GPU (Quick Sync), Plex can offload transcoding to the GPU. First check that a render device is present:
ls -l /dev/dri
crw-rw---- 1 root video 226, 0 ... card0
crw-rw---- 1 root render 226, 128 ... renderD128
Add the plex user to the render and video groups and restart the service:
sudo usermod -aG render,video plex
sudo systemctl restart plexmediaserver
In Settings > Transcoder, enable Use hardware acceleration when available and Use hardware-accelerated video encoding. Start a stream that needs transcoding and open the dashboard (Activity > Dashboard): the stream should show (hw) next to the transcode status.
For NVIDIA cards, install the proprietary driver recommended by ubuntu-drivers devices, reboot, and confirm the GPU with nvidia-smi before enabling the same settings.
Step 7 - Backing up the Plex database
The Plex database, watch history and metadata live in:
/var/lib/plexmediaserver/Library/Application Support/Plex Media Server
Plex already creates periodic copies of its database. Confirm that Settings > Scheduled Tasks > Backup database every three days is enabled. Those copies stay on the same disk, so also keep an off-server archive.
Create a backup script that stops Plex briefly so the database is consistent, archives everything except caches, and deletes archives older than 30 days:
sudo nano /usr/local/bin/plex-backup
#!/usr/bin/env bash
set -euo pipefail
PLEX_DIR="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
BACKUP_DIR="/var/backups/plex"
ARCHIVE="${BACKUP_DIR}/plex-$(date +%F).tar.gz"
mkdir -p "$BACKUP_DIR"
systemctl stop plexmediaserver
trap 'systemctl start plexmediaserver' EXIT
tar -czf "$ARCHIVE" \
--exclude="Cache" \
--exclude="Codecs" \
--exclude="Crash Reports" \
--exclude="Diagnostics" \
--exclude="Logs" \
-C "$(dirname "$PLEX_DIR")" "$(basename "$PLEX_DIR")"
find "$BACKUP_DIR" -name 'plex-*.tar.gz' -mtime +30 -delete
The trap restarts Plex even if tar fails. Make the script executable and run it once:
sudo chmod 755 /usr/local/bin/plex-backup
sudo /usr/local/bin/plex-backup
ls -lh /var/backups/plex
-rw-r--r-- 1 root root 312M ... plex-2026-01-15.tar.gz
Schedule it every Sunday at 04:00 with root's crontab:
sudo crontab -e
0 4 * * 0 /usr/local/bin/plex-backup
Copy /var/backups/plex to another server or object storage with a tool such as rsync or rclone, because a backup on the same disk does not protect against disk loss.
Troubleshooting
The setup page says no server was found. You are probably not using the SSH tunnel, or the tunnel was opened to the wrong port. Reconnect with ssh -L 32400:localhost:32400 ... and open http://localhost:32400/web, not the server's public IP.
Libraries are empty. Check that sudo -u plex ls /srv/media/movies works and that files follow the naming scheme. Then use Scan Library Files from the library's menu.
Remote access shows as not available. Verify sudo ufw status includes 32400/tcp and that the public port in Settings > Remote Access is 32400. The server logs are in the Logs subdirectory of the Plex data directory; Plex Media Server.log records the reachability checks.
Conclusion
Plex Media Server is now running on Ubuntu 24.04 as a systemd service, claimed to your account, serving organized libraries with remote access and a weekly backup. As next steps, invite family members with Settings > Manage Library Access, move media to a dedicated block storage volume as your library grows, and sync the backup archives off the server.
