Download YouTube Videos in Linux Command Line Using youtube-dl

Easily download YouTube videos in Linux using youtube-dl command line tool. With this tool, you can also choose video format and video quality such as 1080p or 4K.
Warp Terminal

There are various ways to download YouTube videos.

But when it comes to Linux, nothing beats youtube-dl. It is a command line based tool, so not everyone's cup of tea. Still, it's a versatile tool that lets you do a lot more than just downloading videos.

I use it to make backups of the videos I have uploaded on It's FOSS YouTube channel.

In this tutorial, I will show you how to use youtube-dl to download videos from YouTube and other websites. I'll also share a few additional examples that you may find useful.

What is youtube-dl?

youtube-dl is a Python-based command-line tool that allows downloading videos from YouTubeDailymotion, Photobucket, Facebook, Yahoo, Metacafe, Depositfiles and a few more similar sites. It is written in pygtk and requires Python interpreter to run this program, it’s not platform restricted. It should run on any Unix, Windows or in Mac OS X based systems.

The youtube-dl tool supports resuming interrupted downloads. If youtube-dl is killed (for example, by Ctrl-C or due to loss of Internet connectivity) in the middle of the download, you can simply re-run it with the same YouTube video URL. It will automatically resume the unfinished download as long as a partial download is present in the current directory. Which means you don’t need download managers in Linux just for resuming downloads.

youtube-dl features

This tiny tool offers so many features that it won’t be an exaggeration to call it the best YouTube downloader for Linux.

  • Download videos from not only YouTube but other popular video websites like Dailymotion, Facebook etc
  • Allows downloading videos in several available video formats, such as MP4, WebM etc.
  • 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.
  • Automatic pause and resume of video downloads.
  • Allows to bypass YouTube geo-restrictions.
🚧
Attention! Downloading videos from websites could be against their policies. It’s up to you if you decide to download videos. Furthermore, there is no release for this tool because of various copyright issues of the past.

How to install youtube-dl on Linux

youtube-dl is a popular program and, is available in the default repositories of most Linux distributions, if not all. But unfortunately, you cannot use these standard packages in your distribution. They are old and most probably don’t work. You can get a working youtube-dl either from the official GitHub repository, or from the youtube-dl nightly release.

Install youtube-dl Nightly

youtube-dl offers a nightly release, which contains recent changes and fixes so that you can run it without any error. I will describe the easiest way to set it up. First go to the Nightly release GitHub page.

Here, you can get a python file, named youtube-dl. Just download it. Once downloaded, copy that file to /usr/local/bin/. For this, open a terminal where you downloaded the file and then run:

sudo cp youtube-dl /usr/local/bin/

Now, give the file the required permissions using the chmod command.

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

You cannot just run youtube-dl now, because of issue with python naming. It uses python while in Ubuntu-based systems, it is python3. So, you can create an alias for youtube-dl in your .bashrc.

alias youtube-dl='python3 /usr/local/bin/youtube-dl'

That’s it. You have set up youtube-dl in your system.

Alternatively, compile from Git Master

If you are running an Ubuntu-based Linux distribution, you can install the tools needed to compile youtube-dl using the command below:

sudo apt install build-essential git

Now, clone the git repository and make the youtube-dl:

git clone https://github.com/ytdl-org/youtube-dl.git
cd youtube-dl/
make youtube-dl

Once you made youtube-dl, you need to copy it to a location in the path. Use the command below:

sudo cp youtube-dl /usr/local/bin/

As in the previous case, if you run youtube-dl from the command line, you will get an error about python because it tries to run using python while in Ubuntu, it is python3. You can create an alias on your .bashrc like:

alias youtube-dl='python3 /usr/local/bin/youtube-dl'

You can now use youtube-dl command.

Important: Keep your youtube-dl updated

Once installed, you can update it to the latest version using this command. This is helpful when you have been using it for a few months:

youtube-dl -U
Update youtube-dl version through Linux terminal
Update youtube-dl

Using YouTube-dl for downloading videos

To download a video file, simply run the following command. Where, “VIDEO_URL” is the URL of the video that you want to download.

youtube-dl <video_url>
Download a Video using the basic youtube-dl command.
Download a Video

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

Download YouTube videos in various formats and quality size

These days, YouTube videos have different resolutions, you first need to check available video formats of a given YouTube video. For that run, youtube-dl with -F option. It will show you a list of available formats.

youtube-dl -F <video_url>

Its output will be like:

Get the available resolutions of a video using the youtube-dl command.
Get Available Resolutions

Now among the available video formats, choose one that you like. For example, if you want to download it in MP4 version and 1080 pixel, you should use:

youtube-dl -f 137 <video_url>

Download subtitles of videos using youtube-dl

First, check if there are subtitles available for the video. To list all subs for a video, use the command below:

youtube-dl --list-subs <video_url>

To download all subs, but not the video:

youtube-dl --all-subs --skip-download <video_url>

Download entire YouTube playlist

To download a playlist, simply run the following command. Where, “playlist_url” is the URL of the playlist that you want to download.

youtube-dl -cit <playlist_url>

Download only audio from YouTube videos

You need ffmpeg installed on your system to download audio from videos. If not already installed, open a terminal and run:

sudo apt install ffmpeg

If you just want to download the audio from a YouTube video, you can use the -x option to simply extract the audio file from the video.

youtube-dl -x <video_url>

The file format is M4A/Ogg, which you may not like. You can specify the file format of the audio file in the following manner:

youtube-dl -x --audio-format mp3 <video_url>

And a lot more can be done with youtube-dl

youtube-dl is a versatile command line tool and provides a number of functionalities. No wonder it is such a popular command line tool.

I have only shown some of the most common usages of this tool. But if you are keen to explore its capabilities further, please check its manual.

I hope this article helped you to download YouTube videos on Linux. If you have questions or suggestions, please drop a comment below.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.