How to Use YouTube-dl to Download Videos on Terminal

Published:9 August 2023 - 5 min. read

Nicholas Xuan Nguyen Image

Nicholas Xuan Nguyen

Read more tutorials by Nicholas Xuan Nguyen!

Today’s sponsor is n8n, the AI-native workflow automation tool built for ITOps and DevSecOps. With 100+ templates to get you started quickly and a powerful visual editor, you can automate complex workflows without giving up control. Check it out here.

 

 

 

 

 

In this digital era where multimedia content reigns supreme, having the ability to download videos effortlessly has become an essential skill. If you are eager to elevate your video downloading game to the next level, why not learn how to use YouTube-dl (now yt-dlp)?

yt-dlp lets you download YouTube videos via your terminal by running a single command. And in this tutorial, you will learn how to download YouTube videos and extract audio only.

Keep reading and start downloading videos like a pro!

Prerequisites on How to Use YouTube-dl

This tutorial comprises hands-on demonstrations in downloading videos. Ensure you have the following in place to follow along:

  • A Linux system – This tutorial uses Ubuntu 20.04.
  • Python 3 and Git installed on your machine.
  • A user with full sudo privileges.

Installing the yt-dlp CLI Tool on Ubuntu

yt-dlp is a versatile and compact command-line program that facilitates video downloads from YouTube and many other video-sharing websites.

Unlike traditional applications with GUIs, yt-dlp operates directly through the command line. Installing this tool provides a powerful and flexible way to retrieve your favorite videos with just a one-line command.

To install yt-dlp on your system, follow these steps:

1. Open your terminal and run the following apt update command to update the local package index to ensure your system is up-to-date.

sudo apt update -y
how to use youtube-dl - Updating the local package index
Updating the local package index

2. Next, execute the below python command to verify the current Phyton 3 version installed.

python3 -V
Verifying the current installed Python 3 version
Verifying the current installed Python 3 version

3. With Python 3 verified, run the apt install command below to install the PIP package manager.

PIP will help streamline the installation process of the YouTube-dl tool on your system. A single command is all it takes to install YouTube-dl and the required dependencies.

sudo apt install python3-pip

When prompted, type y and press Enter to continue with the installation.

Installing the PIP package manager
Installing the PIP package manager

4. Execute the following command to check the current PIP version installed.

sudo pip3 --version
Verifying the PIP installed version
Verifying the PIP installed version

5. Now, run the below command to install yt-dlp via PIP. yt-dlp is a fork of the youtube-dl command-line video downloading tool.

💡 The primary purpose of yt-dlp is to carry on the legacy of youtube-dl. Moreover, to continue the development of new features and improvements while staying in sync with the original youtube-dl project.

This command installs the latest development version (also known as the master branch) of yt-dlp directly from its GitHub repository.

The --force-reinstall flag ensures that the package is reinstalled even if it was already installed, which helps update the latest version.

sudo python3 -m pip install -U pip setuptools wheel && sudo python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz>
Installing yt-dlp using PIP
Installing yt-dlp using PIP

💡 Optionally, run the below command to install the latest stable version of yt-dlp instead. In this command, the pip module runs as a script within the Python interpreter to ensure you use the pip associated with Python 3.

sudo python3 -m pip install yt-dlp
Installing the latest stable release version of yt-dlp
Installing the latest stable release version of yt-dlp

6. Once installed, execute the command below to verify your yt-dlp installation.

sudo yt-dlp --help

You will see a similar output as below if everything goes well.

Verifying the yt-dlp installation
Verifying the yt-dlp installation

Upgrading the yt-dlp CLI Tool to the Latest Version

Exciting new features and enhancements await in each yt-dlp release. On that note, staying updated is essential to harness this tool’s full potential.

Upgrading ensures you enjoy the latest improvements, unleashing a more robust and feature-rich video downloading experience.

Execute the below command to upgrade (-Up) the yt-dlp CLI Tool to the latest version. This command automatically replaces any older version of yt-dlp you have on your system.

sudo python3 -m pip install -U yt-dlp

The output below shows the Requirement already satisfied messages since you installed the latest yt-dlp version

Upgrading the yt-dlp CLI Tool to the latest version
Upgrading the yt-dlp CLI Tool to the latest version

Installing FFmpeg for Enhanced Video Downloading Capabilities

Typically, you would want to download videos of the highest quality possible. Installing FFmpeg, a powerful multimedia framework, provides tools for processing audio and video files.

Execute the following command install ffmpeg on your system.

sudo apt-get install ffmpeg -y
Installing FFmpeg
Installing FFmpeg

Once installed, run the below command to verify if FFmpeg is appropriately installed.

ffmpeg -version
Verifying the FFmpeg is adequately installed
Verifying the FFmpeg is adequately installed

Downloading YouTube Videos via the yt-dlp CLI Tool

With enhanced downloading capabilities, you can download your favorite YouTube videos. How? Downloading videos only takes a single command so long as you have a YouTube video’s URL.

💡 While the name might suggest yt-dlp is only for downloading YouTube videos, this tool supports many video streaming websites.

To download a YouTube video via the yt-dlp CLI tool:

1. Open your web browser, navigate to YouTube, search for a video to download, and copy its URL.

2. Next, run the following yt-dlp command to download your preferred YouTube video. Ensure you replace the URL below with the one you copied in step one.

yt-dlp https://www.youtube.com/watch?v=_jco9nMMPr8

yt-dlp begins fetching the video from YouTube and displays the download progress in the terminal. The video is saved in your current working directory with the same name as the video on YouTube.

Note down the name of the file (The Ultimate Guide to Robocopy) or at least the video ID (i.e., _jco9nMMPr8) for later use.

Downloading a YouTube video
Downloading a YouTube video

3. Lastly, run either ls command below to verify your downloaded video file.

# Verify the downloaded video via the exact file name
ls -la "The Ultimate Guide to Robocopy [_jco9nMMPr8].mp4"
# Verify the downloaded video via the video ID
ls -la | grep "_jco9nMMPr8"
Verifying the downloaded video file
Verifying the downloaded video file

Downloading Audio-Only From a YouTube Video

You have just made your first YouTube video download, but what if you are only after the audio? After all, videos consume more space than audio.

Worry not! The yt-dlp tool lets you extract audio from a video, which is particularly useful if you are interested in music or podcast content only.

To extract and download the audio of a YouTube video:

Execute the following command, replacing <YT_URL> with your preferred YouTube video’s URL to extract and save the audio in mp3 format.

You can also choose different audio formats, such as AAC or M4A, by changing the --audio-format mp3 parameter to the desired format.

💡 Downloading audio-only from a YouTube video opens possibilities like creating audiobooks. Moreover, opting for audio-only downloads helps conserve bandwidth, especially if you have a limited data plan, as video files are generally larger than audio files.

yt-dlp --extract-audio --audio-format mp3 <YT_URL>
Downloading audio-only from a YouTube video
Downloading audio-only from a YouTube video

Once the process completes, run the command below to list (ls) all (-a) audio files that are in mp3 format in your working directory

ls -la *.mp3
Listing all audio files that are in mp3 format
Listing all audio files that are in mp3 format

Downloading Videos Through a Proxy

In some instances, you may encounter restrictions or limitations while downloading YouTube videos directly from your network. The solution? Downloading the videos through a proxy.

By routing your video download requests through a proxy server, you bypass such restrictions and enjoy seamless video downloads.

Run the below yt-dlp command, replacing the following, to download a video through a proxy:

  • [USERNAME:PASSWORD@PROXY_ADDRESS:PORT] – The appropriate credentials and proxy details.
  • [YT_URL] – The URL of the YouTube video to download.
yt-dlp --proxy [USERNAME:PASSWORD@PROXY_ADDRESS:PORT] [YT_URL]
Downloading videos through a proxy
Downloading videos through a proxy

Finally, execute the following command to verify your downloaded video file.

ls -la | grep "_jco9nMMPr8"
Verifying the video file downloaded through proxy
Verifying the video file downloaded through proxy

Conclusion

Throughout this tutorial, you have learned how to use YouTube-dl (now yt-dlp) CLI tool to download videos from YouTube with just a single command. But yt-dlp goes beyond just YouTube, making this tool a versatile and potent utility for grabbing online content.

With yt-dlp at your disposal, you can quickly download your favorite videos and extract audio to create audiobooks.

Now, what’s next? yt-dlp offers many options and parameters for fine-tuning your video downloads. Explore the official documentation to discover advanced features like custom formats, subtitles, metadata, and more!

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!