How to Install Plex Media Server on Ubuntu 24.04, 22.04, or 20.04

Plex Media Server is a pivotal solution for streaming enthusiasts seeking to organize and access their media libraries seamlessly from various devices. Its ability to transcode media files on the fly ensures compatibility across different platforms, making it indispensable for a unified streaming experience.

Key features of Plex Media Server include:

  • Centralized Media Library: Consolidates your videos, music, and photos in one easy-to-navigate platform.
  • On-the-Fly Transcoding: Converts media to the optimal format for each device, enhancing playback quality.
  • Remote Access: Stream your content from anywhere, on any device with internet access.
  • User-Friendly Interface: Offers a visually appealing and intuitive navigation experience.
  • Customizable Playlists and Libraries: Tailor your viewing or listening experience by creating personalized collections.
  • Extensive Device Support: Compatible with various devices, from smartphones to smart TVs.
  • Secure Sharing: Safely share selected content with friends and family.
  • Regular Updates: Continuously improves with new features and enhancements.

Transitioning from highlighting Plex’s robust features to setting it up on your Ubuntu system is straightforward. Let’s dive into the technical steps to get Plex Media Server up and running.

Install Plex Media Server via Plex APT Repository

Update Ubuntu Before Plex Installation

Before proceeding with the tutorial, ensuring your system is up-to-date with all existing packages is good.

sudo apt update

Proceed to upgrade any outdated packages using the following command.

sudo apt upgrade

Import Plex Media Server APT Repository

For the Plex Media server installation, you must create a repository file that pulls directly from the Plex repository. This ensures you install and update straight from the official source using the apt package manager.

First, ensure the following packages are installed:

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl -y

Import the GPG key using the following terminal command.

curl -fsSL https://downloads.plex.tv/plex-keys/PlexSign.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/plex.gpg

Next, import the repository with the following command.

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

Install Plex Media Server via APT Command

Run the apt update command to reflect the new repository imported before installing Plex:

sudo apt update

Install the Plex Media Server on Ubuntu using the following apt install command:

sudo apt install plexmediaserver

Verify Plex Media Player Service Status

By default, the Plex Media service should start automatically. Verify this by using the following systemctl status command.

systemctl status plexmediaserver

If the service is not active, use the following command to start Plex Media Server:

sudo systemctl start plexmediaserver

Next, enable on system boot:

sudo systemctl enable plexmediaserver

To restart the service, use the following:

sudo systemctl restart plexmediaserver

Configure Plex Media Server UFW Firewall (Optional)

Before proceeding, configure your UFW firewall. By default, the firewall should be enabled for most users. If not, enable it with the following command:

sudo ufw enable

Add the Plex Media Server port 32400; you can customize the port later. Ensure you delete this rule if you allow another and swap it in the Plex Media server dashboard:

sudo ufw allow 32400

Configure Ubuntu Server SSH on Ubuntu For Plex

Users with Plex Media Server on a remote Ubuntu server must set up an SSH tunnel on their local computers for initial setup to enable outside connections.

Replace {server-ip-address} with your specific example, such as 192.168.50.1.

Example:

ssh {server-ip-address} -L 8888:localhost:32400

For users new to SSH, you may need to install it.

sudo apt install openssh-server -y

Next, start the service.

sudo systemctl enable ssh -y

Now, you can access the Plex Media Server by accessing the localhost in your web browser.

http://localhost:8888/web

Or the alternative if the above address does not work.

localhost:32400/web/index.html#!/setup

Through an SSH tunnel, the HTTP request redirects to http://localhost:32400/web on the remote server. After the initial setup, access your Plex Media Server using the remote server’s IP address.

https://{server-ip-address}:32400

Finalize Plex Media Server in Web-UI

After installing Plex on your system, configure and complete the setup via the WebUI. Open your preferred Internet browser and navigate to http://127.0.0.1:32400/web or http://localhost:32400/web.

Now, you can log in using an existing social media account listed above or register a new account using your e-mail if you are new to Plex. Once logged in, you will begin the initial configuration setup.

How Plex Works

The first configuration page describes Plex and how it works in a concise example.

Navigate to GOT IT! and leave a click to proceed to the next page.

Depending on your Internet browser, you may need to take specific actions. Firefox users, for instance, will see a message that prompts them to enable DRM

Note: Enabling DRM is necessary for the proper function of Plex WebUI; without it, the interface may malfunction on Firefox-based browsers.

Optional: Plex Pass

You may see a prompt for you to upgrade to Plex Pass, which is optional. Plex Pass offers HDR options and access to Beta builds.

If you prefer to skip this, click the “X” in the top right-hand corner.

Plex Server Setup

Name your server, choosing any name you desire. You also have the option to disable the “Allow me to access my media outside my home” feature. The system enables access to outside media by default; untick the feature if you don’t need it.

Once configured, click the NEXT button.

Add or Skip Plex Media Library Section

The Media Library page gives you the option to pre-add your media directories.

If you have a media drive or folder ready, click the ADD LIBRARY button.

Select the media type for organizing your folders: TV shows, movies, music, etc.

Click the NEXT button to proceed to add folders.

Click the BROWSE FOR MEDIA FOLDER button and select the media directory.

Note: As often happens, you can skip this step and add media later.

The last option is the Advanced option, which appears once the folder is added. Here, you can further customize Plex to your liking.

Once done, click ADD LIBRARY to continue back to the initial configuration setup installation.

Finishing Up Plex Server Configuration

Next, hit the NEXT button to finish the initial setup with or without adding a Media Library. The next screen informs you that you are all set.

Click the DONE button to proceed to the Plex Dashboard.

Now, you will arrive at your Plex Dashboard.

Setting Up Media File and Folder Permissions for Plex

When configuring the Plex Media Server on Ubuntu, ensure the Plex service has the necessary permissions to access your media files. Plex operates under a dedicated user account, typically named plex. This account must have read and executed permissions on the media directories to successfully scan and add content to your Plex library. Here, we outline how to adjust permissions using chown and setfacl, two command-line utilities available in Ubuntu.

Adjusting Permissions with setfacl

The setfacl command allows for fine-grained access control list modifications. This method is particularly useful for setting permissions without changing the ownership of the directories and files. Before proceeding, ensure the ACL package is installed on your system. If not, you can install it with the following command:

sudo apt install acl -y

After installing the ACL package, apply the necessary permissions using setfacl by executing the commands below. Replace /media/yourfolder/ with the actual path to your media folders.

sudo setfacl -R -m u:plex:rx /media/yourfolder/
sudo setfacl -R -m u:plex:rx /media/yourfolder/tv
sudo setfacl -R -m u:plex:rx /media/yourfolder/movies

These commands recursively (-R) modify the access control list for the plex user, granting read (r) and execute (x) permissions to your media directories.

Setting Permissions with chown

Alternatively, you can change the ownership of the media directories to the plex user with chown command. This approach is straightforward but alters the ownership of the files and folders, which might affect access for other users. Use chown as follows:

To change ownership of the entire media directory:

sudo chown -R plex:plex /media/yourfolder/

For specific media types within the directory, ensure Plex only accesses designated folders:

sudo chown -R plex:plex /media/yourfolder/tv
sudo chown -R plex:plex /media/yourfolder/movies

These commands recursively change the ownership of the specified directories to plex, allowing the Plex Media Server full access to these files.

Configure Nginx as a Reverse Proxy For Plex Media Server (Optional)

You can set up a reverse proxy to access Plex Media Server from a remote computer or network. This tutorial will set up an Nginx proxy server.

First, install Nginx:

sudo apt install nginx -y

Ensure that Nginx is activated and error-free:

systemctl status nginx

If Nginx is not enabled by default, activate it using the following command:

sudo systemctl enable nginx --now

Now, create a new server block as follows:

sudo nano /etc/nginx/conf.d/plex.conf

After you have created your sub-domain, add the following to the server block file:

server {
      listen 80;
      server_name plex.example.com;

      location / {
          proxy_pass http://127.0.0.1:32400;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

          #upgrade to WebSocket protocol when requested
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "Upgrade";
      }
}

Save the file (CTRL+O), then exit (CTRL+X).

Now do a dry run to make sure there are no errors in the Nginx configuration or your server block:

sudo nginx -t

If everything is working correctly, the example output should be:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx for the change to take effect:

sudo systemctl reload nginx

If you have set up your domain and DNS records to point to your server IP, you can now access your Plex Media Server at plex.example.com.

Secure Nginx with Let’s Encrypt SSL Free Certificate For Plex Media Server

Run your Nginx on HTTPS using a Let’s Encrypt SSL certificate. Let’s Encrypt is a free, automated, open certificate authority operating under the nonprofit Internet Security Research Group (ISRG).

First, execute the following command to install the certbot package:

sudo apt install python3-certbot-nginx -y

After installation, initiate your certificate creation with this command:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com

During installation, a notice will appear asking if you want to receive e-mails from the Electronic Frontier Foundation (EFF). Select ‘Y’ or ‘N’, and the system will automatically install and configure your TLS certificate.

This setup automatically applies force HTTPS 301 redirects, adds a Strict-Transport-Security header, and enables OCSP Stapling. Ensure you replace the placeholder e-mail and domain name with your actual information.

Your URL will then change from HTTP://www.example.com to HTTPS://www.example.com, with the old HTTP URL automatically redirecting to HTTPS.

For automatic certificate renewal, consider setting up a cron job. Certbot provides a script for this purpose. Run a dry test to ensure functionality:

sudo certbot renew --dry-run

If successful, open your crontab window with the terminal command:

sudo crontab -e

Then, set the auto-renewal schedule. Check for renewal daily; the script will update the certificate if needed.

00 00 */1 * * /usr/sbin/certbot-auto renew

Additional Commands with Plex Media Server

Update Plex Media Server

Update Plex using the standard apt update command that you typically use to upgrade packages on your system.

To check for updates:

sudo apt update

If one is available, use the upgrade command:

sudo apt upgrade plexmediaserver

Remove Plex Media Server

To remove Plex from your Ubuntu system, run the following command:

sudo apt remove plexmediaserver

If you have installed the Nginx reverse proxy, disable it and delete your domain’s configuration file as necessary.

Then, if you don’t plan to reinstall Plex, delete the repository in /etc/apt/sources.list.d/ with:

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

Finally, for enhanced security and maintenance, remove the GPG key from usr/share/keyrings/:

sudo rm usr/share/keyrings/plex.gpg

Conclusion

In this guide, we walked through the steps to install Plex Media Server on Ubuntu 24.04, 22.04, and 20.04 LTS. By tapping into the command-line terminal and the official Plex repository, you’re now equipped with the latest version of a powerful media server. As you dive into Plex, explore its features like remote access and on-the-fly transcoding to maximize your media collection. Keep your server updated for a smooth streaming experience. And hey, don’t hesitate to securely share your favorite movies or shows with friends and family through Plex. Happy streaming!

Useful Links

Here are some valuable links related to using Plex:

  • Plex Official Website: Visit the official Plex website for information about Plex Media Server, its features, and download options.
  • Plex Support: Access the Plex support page for troubleshooting, guides, and FAQs to help resolve issues and optimize your Plex experience.
  • Plex Forums: Join the Plex community forums to discuss issues, share solutions, and get support from other Plex users.

3 thoughts on “How to Install Plex Media Server on Ubuntu 24.04, 22.04, or 20.04”

    • I have not installed Plex Media Server on a 32-bit system before, but technically, it should if your architecture is supported. If it isn’t, then you will not be able to install it.

      Just remove the source if it does not work, it will not take you long to test. Plex from memory does support 32bit.

      Reply
    • Forget my previous answer as I misread your question. Yes, it is installable on a 64-bit system. Most of my guides are done on 64-bit architecture, as it is the main one used by many Linux users.

      Reply

Leave a Comment