Download YouTube Video From the Linux Command Line

We can download YouTube video files from the Linux command line using a program, called youtube-dl.

It is a small python command-line program that can download videos from and a few more sites.

In this article you'll find how to install YouTube downloader on your Linux system, depending on your distribution.

You'll also learn how to download YouTube video, channel or playlist of any available quality and formats from the Linux shell.

Install Linux Command Line YouTube Downloader

One of the easiest way to install the latest youtube-dl package is to use command line tool, called pip - python package installer.

Install YouTube Downloader -- Linux Mint, Ubuntu, Debian

Install pip :

$ sudo apt-get install python-pip

Install youtube-dl on Linux Mint, Ubuntu or Debian :

$ sudo pip install --upgrade youtube_dl

Install YouTube Downloader -- CentOS, RHEL

There is no pip package in default CentOS and RHEL repositories, but it can be found in EPEL.

Add EPEL Repository on your distribution.

After EPEL repository is enabled, you can install pip :

$ sudo yum install python-pip

Install youtube-dl on CentOS or RHEL :

$ sudo pip install --upgrade youtube_dl

Download YouTube Videos From the Linux Command Line

By default, youtube-dl downloads a file in a best available quality and format.

To download a video file from YouTube, simply run youtube-dl, as follows :

$ youtube-dl <VIDEO URL>

Example : Download the video

$ youtube-dl

Quality And Formats Of YouTube Video Files

Use the option -F to list all available formats :

$ youtube-dl -F
[youtube] Setting language
[youtube] hTWKbfoikeg: Downloading webpage
[youtube] hTWKbfoikeg: Downloading video info webpage
[youtube] hTWKbfoikeg: Extracting video information
[youtube] hTWKbfoikeg: Encrypted signatures detected.
[youtube] hTWKbfoikeg: Downloading js player vflBb0OQx
[info] Available formats for hTWKbfoikeg:
format code extension resolution  note 
171         webm      audio only  DASH audio , audio@ 48k (worst)
140         m4a       audio only  DASH audio , audio@128k
160         mp4       144p        DASH video , video only
133         mp4       240p        DASH video , video only
242         webm      240p        DASH video , video only
17          3gp       176x144     
36          3gp       320x240     
5           flv       400x240     
18          mp4       640x360     
43          webm      640x360     (best)

To download a preferred file format, use the option -f with the format code that can be taken from the output of the previous command.

For example, if we need to download YouTube video in the FLV format with the resolution 400x240, we have to pick format code 5 :

$ youtube-dl -f 5

Download a List Of YouTube Video Files

To download a list of video files from YouTube, create a file links.txt, place all the links that you need to download and run the youtube-dl as follows :

$ youtube-dl -a links.txt

Download Entire YouTube Channel

Download an entire YouTube channel of some USER:

$ youtube-dl -citw ytuser:<USER>

Example : Download the entire YouTube channel of the user NirvanaVEVO

$ youtube-dl -citw ytuser:NirvanaVEVO

Download All YouTube Videos On a PlayList

Download all YouTube videos on some playlist :

$ youtube-dl -citw <PLAYLIST URL>

Example : Download all YouTube videos on the playlist

$ youtube-dl -citw

Read man to learn more about youtube-dl :

$ man youtube-dl