How to Download YouTube Videos From Linux Command Line

In this blog post, we will show you how to download youtube videos from linux command line using yt-dlp.

yt-dlp is an advanced fork of the well-known youtube-dl project, designed to offer additional features and improvements. This command line tool allows users to effortlessly download videos, playlists, and even entire channels from YouTube and various other supported sites.

Installing yt-dlp

Before we delve into the process, let’s start by installing yt-dlp on your Linux system. Open your terminal and run the following commands:

Ubuntu / Debian

$ sudo apt update 
$ sudo apt install yt-dlp -y

Install-yt-dlp-in-linux-apt-command

RHEL / Fedora / Rocky Linux / AlmaLinux

First install EPEL repository and then run following command.

$ sudo yum install yt-dl -y 
or 
$ sudo dnf install yt-dlp-y

Arch Linux

$ sudo pacman -S yt-dlp

OpenSUSE

$ sudo zypper install yt-dlp -y

In order to install latest version of yt-dlp then run following curl and chmod command.

$ sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
$ sudo chmod a+rx /usr/local/bin/yt-dlp

Post yt-dlp installation, verify its version run,

$ yt-dlp --version
2023.10.07
$

Download YouTube Videos From Linux Command Line

Now that you have yt-dlp installed, let’s explore the simple steps to download YouTube videos using the command line.

Use the following command to download a single video

$ sudo yt-dlp <video_url>

Replace <video_url> with the URL of the YouTube video you want to download.

For example:

$ sudo yt-dlp https://www.youtube.com/watch?v=lSSJ0uHKw-I

Download-Youtube-Videos-From-Linux-Command-Line-Yt-Dlp

If you want to download an entire playlist, use the following command:

$ sudo yt-dlp -i –yes-playlist <playlist_url>

Replace <playlist_url> with the URL of the YouTube playlist.

For example:

$ sudo yt-dlp -i --yes-playlist https://www.youtube.com/playlist?list=PLdhnFRBswMUgVs5RY76heVrYlh6uEdpqv

Download-YouTube-Playlist-Linux-Command-Line-Yt-Dlp

Choosing Video and Audio Quality:

One of the highlights of yt-dlp is its ability to let you customize your downloads. You can choose specific video and audio quality options according to your preferences.

For example, to download the best video and audio quality available, use the following command:

$ sudo yt-dlp -f bestvideo+bestaudio <Video-URL>

If you prefer a specific video quality, you can specify it using:

$ sudo yt-dlp -f 'bestvideo[height<=720]+bestaudio/best[height<=720]' <Video-URL>

In order to download high-quality YouTube video and audio, use the following command.

$ sudo yt-dlp -f best <Video-URL>

If you’re interested in just the audio, you can use the following command:

$ sudo yt-dlp -x --audio-format mp3 <Video-URL>

To list all available format codes for the video, run

$ sudo yt-dlp -F <Video-URL>

Example,

$ sudo yt-dlp -F https://www.youtube.com/watch?v=NIUR75XO5mM

Availble-Video-Codes-Yt-Dlp-Linux-Command-Line

To download the video along with the subtitles, run following command.

$ sudo yt-dlp --sub-langs all <video_url>  
or 
$ sudo yt-dlp --sub-langs "en.*" <video-url>

In order to list all available sub-titles of a video, run

$ sudo yt-dlp --list-sub <Video-URL>

That’s all from this post, We hope you have found it informative and useful. Kindly do post your queries and feedback on below comments section.

1 thought on “How to Download YouTube Videos From Linux Command Line”

Leave a Reply to Pranish Cancel reply