Raspberry Pi as Plex Media Server

This post covers installing Plex Media Server on a Raspberry Pi 4 B and keeping Plex up to date.

Plex is in my opinion the best way to enjoy your media. Whether it’s your old DVD collect, Live TV or family photos, Plex can make it look beautiful and easy to access.

The brain of Plex is Plex Media Server.
In this post I will walk through two methods of installing Plex Media Server on your Raspberry Pi.

This is part 4 of 4 in a mini series where we will configure a headless Raspberry Pi 4 B as an efficient home server, capable of hosting Network Attached Storage (NAS), TimeMachine and Plex Media Server.
Through this series we will also look at how we can make automatic backups to keep uor data safe.

Prerequisites

Hardware Requirements

Software Requirements


Download and Install from plex.tv

The easiest way to get Plex Media Server installed on your Raspberry Pi is downloading it right off the official downloads page:

Browse to: https://www.plex.tv/media-server-downloads/#plex-media-server

You need to know which architecture your Raspberry Pi OS is running. You can get this information with the lscpu command:

lscpu

[output]

pi@raspberrypi:~ $ lscpu
Architecture:                    armv7l
Byte Order:                      Little Endian
CPU(s):                          4
On-line CPU(s) list:             0-3
Thread(s) per core:              1
Core(s) per socket:              4
Socket(s):                       1
Vendor ID:                       ARM
Model:                           3
...

Look for the line that says Architecture:

Then download the Debian version matching your architecture.
You can do this directly from the console on your Raspberry Pi with wget (remember to use an updated link):

wget https://downloads.plex.tv/plex-media-server-new/1.30.2.6563-3d4dc0cce/debian/plexmediaserver_1.30.2.6563-3d4dc0cce_armhf.deb

Finally install Plex Media Server with dpkg (replacing the file name with the package you downloaded):

sudo dpkg -i plexmediaserver_1.30.2.6563-3d4dc0cce_armhf.deb

You can now access your Plex Media Server in your from your Raspberry Pi’s IP on port 32400 e.g. http://192.168.0.200:32400 or on http://raspberrypi.local:32400 if you installed Avahi in part 3 (you do not need to configure Avahi - just install it).


There you have it, Plex Media Server, Installed!


Update from plex.tv

To update your Plex Media Server installation, you can simply follow the install instructions again from the top, and install the updated version on top of your existing install.

Install from official Plex repository

The best way of installing Plex Media Server and keeping it up to date is with apt directly from the official Plex repository.

This however requires a bit of setting up first. It is well worth it in the end though, as it makes updating your Plex Media Server installation a lot easier.

Setup official Plex repository

First you need to install apt-transport-https.
This allows the apt package manager to install packages over the https protocol which the Plex repository uses:

sudo apt update
sudo apt install apt-transport-https

Then you need to download the Plex gpg key using wget and add it to your keyring:

wget -O- https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor | sudo tee /usr/share/keyrings/plex-archive-keyring.gpg > /dev/null

Here the gpg command is used to unpack the ASCII armor of the the PlexSign.key and pipe the content to the tee command, that is in turn is used to pipe the content in to the plex-archive-keyring.gpg, because access to the /usr/share/keyrings/ directory requires super user access. The output is then redirected to /dev/null as it is not needed.

After that you can add the official Plex deb repository to the sources:

echo deb [signed-by=/usr/share/keyrings/plex-archive-keyring.gpg] https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list

Here echo is used to transform the text deb [signed-by=/usr/share/keyrings/plex-archive-keyring.gpg] https://downloads.plex.tv/repo/deb public main in to an output stream that can be piped to the tee command.


Install Plex Media Server from official Plex repository

With the official Plex repository added, you need to run apt update again, to refresh the package list.
Then you can install Plex Media Server:

sudo apt update
sudo apt install plexmediaserver

You can now access your Plex Media Server in your from your Raspberry Pi’s IP on port 32400 e.g. http://192.168.0.200:32400 or on http://raspberrypi.local:32400 if you installed Avahi in part 3 (you do not need to configure Avahi - just install it).


There you have it, Plex Media Server, Installed!


Update from official Plex repository

When a new version is released, you can simply update Plex Media Server with apt:

sudo apt update
sudo apt install --only-upgrade plexmediaserver

Troubleshooting: Updating from repository

During the installation process, the official Plex repository is sometimes disabled. To enable the repository, open the plexmediaserver.list file in nano and uncomment the line starting with “deb”:

sudo nano /etc/apt/sources.list.d/plexmediaserver.list

The contents of your plexmediaserver.list file should look like to this:

deb [signed-by=/usr/share/keyrings/plex-archive-keyring.gpg] https://downloads.plex.tv/repo/deb public main

Update Plex Media Server Automatically

Whether you downloaded and installed Plex Media Server from the downloads page on plex.tv or from the official Plex repository with apt, it is easy to keep your installation up to date automatically.

Note:
If you followed Download and Install from plex.tv, you first have to Setup official Plex repository before continuing.

With the official Plex repository set up on your Raspberry Pi, you are now ready to automate the Plex Media Server update process.

First, create a new file with touch and set execution permissions with chmod:

touch ./Documents/plex-mediaserver-update.sh
chmod +x ./Documents/plex-mediaserver-update.sh

Then edit the file in nano:

nano ./Documents/plex-mediaserver-update.sh

And paste the following:

#!/bin/bash

sudo apt update
sudo apt install --only-upgrade plexmediaserver

Open crontab with the commend:

crontab -e

At the end of the document, type the frequency of script execution in the following manner

0 5 * * 1 /home/pi/Documents/plex-mediaserver-update.sh

The above line means that the script with run At 05:00 on Monday. You can configure this according to your needs. I recommend using crontab.guru to get the right settings for you.

The script will only install an update if one is available, so it is safe to run as frequently as you like.

Backup Plex Media Server Data

“The Plex Media Server data directory contains nearly all the information about your server installation. This includes the database file with your library information as well as metadata, artwork, caches, and more.” - plex.tv

When you have spent time getting your Plex library set up just the way you like it. It can be a god idea to have a backup of the data directory, just in case a something goes wrong and your library gets messed up.

Note:
In part 2 - Raspberry Pi Backup I describe how to mount external storage to your Raspberry Pi and make a backup of the entire microCD Card.
You can reference this section: Setting up the external storage.

With external storage mounted to your Raspberry Pi, you can follow steps similar what you just did in: Update Plex Media Server Automatically.

First, create a new file with touch and set execution permissions with chmod:

touch ./Documents/plex-media-backup.sh
chmod +x ./Documents/plex-media-backup.sh

Then edit the file in nano:

nano ./Documents/plex-media-backup.sh

And paste the following (make sure the BACKUP_DIRECTORY variable is correct for you):

#!/bin/bash

CURRENT_DATETIME=`date +"%Y-%m-%dT%H-%M-%S"`
BACKUP_DIRECTORY="/media/pi/NAS/Plex/BACKUPS"
BACKUP_FILENAME="${BACKUP_DIRECTORY}/PlexMedia-(${CURRENT_DATETIME}).tar.gz"

# Exit script if Backup Directory does not exist
if [ ! -d "${BACKUP_DIRECTORY}" ]; then
  echo "${BACKUP_DIRECTORY} does not exist"
  exit 1
fi

# tar & gzip Plex Media Server Data
sudo tar czPf "${BACKUP_FILENAME}" --exclude="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache" "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/"

# Delete backups older than specified number of days
find ${BACKUP_DIRECTORY} -maxdepth 1 -name "*.tar.gz"  -type f -mtime +90  -delete

Open crontab with the commend:

crontab -e

At the end of the document, type the frequency of script execution in the following manner

0 0 */10 * * /home/pi/Documents/plex-media-backup.sh

The above line means that the script with run At 00:00 on every 10th day-of-month. You can configure this according to your needs. I recommend using crontab.guru to get the right settings for you.

Sources

Christophe Knage · 2023-03-12