How to Install YouTube-DL on Ubuntu 20.04 – A Command Line Video Downloader for Linux

YouTube-dl is a free and open source command-line application to download videos from YouTube and over 1,000 other video hosting websites including Dailymotion, Facebook, Yahoo.

This application is written in pygtk and requires the Python interpreter to run. Its an cross-platform application available for Microsoft Windows, macOS, Linux.

By default youtube-dl tries to download the best available quality, i.e. if you want the best quality you don’t need to pass any special options, youtube-dl will guess it for you by default but sometimes you may want to download in a different format, for example when you are on a slow or intermittent connection.

The key mechanism for achieving this is so-called format selection based on which you can explicitly specify desired format, select formats based on some criterion or criteria, setup precedence and much more.

The general syntax for format selection is --format FORMAT or shorter -f FORMAT where FORMAT is a selector expression, i.e. an expression that describes format or formats you would like to download. You can also use a file extension (currently 3gp, aac, flv, m4a, mp3, mp4, ogg, wav, webm are supported) to download the best quality format of a particular file extension served as a single file.

For example -f webm will download the best quality format with the webm extension served as a single file. The youtube-dl tool supports resuming interrupted downloads.

Key Features of YouTube-DL

  • Download videos from not only YouTube but other popular video websites like Dailymotion, Facebook etc
  • Automatical pause and resume of video downloads.
  • You can also choose the quality of the video being downloaded. If the video is available in 4K, you can download it in 4K, 1080p, 720p etc.
  • Allows to bypass YouTube geo-restrictions
  • Allows downloading videos in several available video formats such as MP4, WebM etc.

To get more information on youtube-dl visit the official github page.

This article explains three methods of installing YouTube-DL on Ubuntu 20.04.

Choose the installation method that is most appropriate for your environment.

Prerequisite:

Type the following command to install Python as YouTube-DL requires the Python interpreter to run.

$ sudo apt update
$ sudo apt install python-is-python3

Method 1: Installing YouTube-DL as a Snap Package

The easiest way to install YouTube-DL on Ubuntu 20.04 is by using the snap packaging system.

A snap package is a type of universal Linux package that you can enjoy irrespective of the distro. Its an self-contained software packages that include the binary all dependencies needed to run the application.

All you need is the snap service pre-configured, In the case of Ubuntu 20.04, it comes with snap pre-installed.

If snapd package is not already installed then you can install it by running following command.

$ sudo apt install snapd

Note: Snap packages can be installed from either the command-line or via the Ubuntu Software application.

This is actually the Snap version of the YouTube-DL. It can be used on any Linux distribution that has Snap support.

Open your terminal (Ctrl+Alt+T) and type the following command to install the YouTube-DL package.

$ sudo snap install youtube-dl

At this step, you have successfully installed YouTube-DL on Ubuntu 20.04 system.

Type the following command to update YouTube-DL package.

$ sudo snap refresh youtube-dl

Method 2: Installing YouTube-DL from Ubuntu apt repository

YouTube-DL is included in Ubuntu 20.04. Follow the step by step guide to install the application.

Step #1

Type the following command to update the apt sources.

$ sudo apt update

Step #2

Now execute this command to install the YouTube-DL package.

$ sudo apt install youtube-dl

With the help of && you can write both the commands in a single line. Something like this:

$ sudo apt update && sudo apt install youtube-dl

That’s it.

Method 3: Installing YouTube-DL from official source repository

If you don’t want to add any third party repository, you can still install it right away using wget or curl command as shown.

Step #1

Type the following command to download the Youtube-dl script using curl and move it to the /usr/local/bin/ directory.

$ sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

If you do not have curl, you can alternatively use a recent wget.

$ sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl

Step #2

After fetching the file, you need to set a executable permission on the script to execute properly.

$ sudo chmod a+rx /usr/local/bin/youtube-dl

Step #3

Once installed, you can update it to the latest version using this command.

$ youtube-dl -U

That’s it.

How to Download videos using YouTube-dl

Downloading videos using YouTube-DL is honestly straightforward. Here are few examples.

1. Use YouTube-DL to Download Videos

To download a video file, simply run the following command.

Syntax:

$ youtube-dl <video_url>

Where video_url is the URL of the video that you want to download.

Example:

$ youtube-dl https://youtu.be/zA3vmx0GaO8

The video is saved in the directory from where you run the command.

2. Download entire YouTube Playlist

Syntax:

$ youtube-dl -cit <playlist_url>

Example:

$ youtube-dl -cit https://youtube.com/playlist?list=PLwhVruPHD9rzGg1jIpLA32IVqlTB1gw-i

3. Download only Audio from YouTube videos

Syntax:

$ youtube-dl -x <video_url>

Example:

$ youtube-dl -x --audio-format mp3 https://youtu.be/t0-_VhLeHv0

Type the following command in terminal to list all the avialable options.

$ youtube-dl --help

How to Uninstall YouTube-DL from Ubuntu 20.04

For some reason, If you want to uninstall YouTube-DL, refer following methods.

Method #1

If you have installed YouTube-DL via Snap type the following command:

$ sudo snap remove youtube-dl

Method #2

If you have installed YouTube-DL from default ubuntu apt respository then uninstall by running the below command:

$ sudo apt remove youtube-dl

Conclusion

I hope that now you have a good understanding of How to Install YouTube-DL on Ubuntu 20.04 LTS Focal Fossa.

If anyone does have any questions about what we covered in this guide then feel free to ask in the comment section below and I will do my best to answer those.

Source:

Leave a Comment