How to Install Plex Media Server on Ubuntu 20.04

Updated on February 4, 2022
How to Install Plex Media Server on Ubuntu 20.04 header image

Introduction

Plex Media Server is a self-hosted streaming solution that gives you the power to control what, when and how you wish to stream media content online. Similar to paid streaming services like Netflix, Plex allows you to access your data on any device with internet access.

In this guide, you will install Plex Media Server on a Ubuntu 20.04 Virtual Private Server (VPS).

Prerequisites

Install Plex Media Server

Set up the Plex repository.

$ curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -

$ echo deb https://downloads.plex.tv/repo/deb public main | sudo dd of=/etc/apt/sources.list.d/plexmediaserver.list

Install Plex Media Server.

$ sudo apt install plexmediaserver

You may receive the following prompts during the installation process; simply press enter (N) to proceed.

Configuration file '/etc/apt/sources.list.d/plexmediaserver.list'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
       What would you like to do about it ? Your options are:
        Y or I  : install the package maintainer's version
        N or O  : keep your currently-installed version
         D     : show the differences between the versions
          Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** plexmediaserver.list (Y/I/N/O/D/Z) [default=N] ?

Verify that Plex is running.

$ systemctl status plexmediaserver

Configure Firewall

Plex uses several ports to communicate and sync media on your server. Make sure you allow each of them on the firewall to avoid any run time errors.

Allow Plex TCP ports.

$ sudo ufw allow proto tcp from any to any port 32400,3005,8324,32469 comment' Plex Media Server TCP'

Allow Plex UDP Ports.

$ sudo ufw allow proto udp from any to any port 1900,5353,32410:32414 comment 'Plex Media Server UDP'

Check the current firewall table if the new rules are listed.

$ sudo ufw status

Then, restart the firewall for rules to take effect.

 $ sudo ufw reload

Setup Plex Media Server

First, create directories to store your media files. For easy and safe access, use your current user home directory.

Create new Images, Music, Movies, and Series subdirectories under the main Media directory.

$ mkdir -p ~/Media/{Movies,Music,Images}

Grant the user plex ownership permissions to the directory.

 $ chown -R plex ~/Media

Then, through a new SSH terminal session, tunnel your server traffic from port 32400 to a random port like 3000 on your localhost with the following command:

Now, visit your localhost address on port 3000 through a web browser.

http://localhost:3000/web

If in any case, XML errors pop up in your browser, change the URL to http://localhost:3000/web/manage

Next, sign in with your Plex account, create one to proceed with a splash screen on how Plex works, and then continue setting up the media server.

Plex Server Naming

Give your server a new name for easy identification. You will be prompted to add a new library, select the type, click Browse for Media Folder, and select the Media folder created earlier in your user home directory.

Plex Library Setup

Click Add Library to save your directory, then repeat the process to add all Media directories. Once all is set, click Done to redirect to the main dashboard and sync all files in your server's Media directory.

Plex Media Server

Note that the first Plex Media Server configuration must be done from a localhost address; else, if you directly visit your server IP address on port 32400, you will not have the option to add Libraries. Alternatively, add a subdomain using Nginx to proxy traffic directly from localhost port 32400.

Configure Nginx to serve Plex on a subdomain

Using your favorite editor, create a new Nginx server block file.

$ sudo vim /etc/nginx/conf.d/plex.conf

Paste the following contents and replace plex.example.com with your actual subdomain.

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


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

}

Save the file.

Test the Nginx configuration

$ sudo nginx -t

Restart Nginx

$ sudo service nginx restart

Conclusion

Congratulations, you have successfully installed Plex Media Server on a Ubuntu 20.04 server. Each time you download or add media content to the server, it will automatically sync to all devices where your Plex account is logged in. To increase your server space for movies and other media, consider attaching a Vultr block storage volume on the server.