Download YouTube Video – 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 youtube.com and 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 see how to download YouTube video, channel or playlist of any available quality and formats from the Linux shell.

Install YouTube Downloader on Linux

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

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

CentOS, RHEL

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

Cool Tip: Install EPEL repository in one command! Read more →

As only 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

Useful information: 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>

For example, to download Nirvana – Smells Like Teen Spirit, run:

$ youtube-dl https://www.youtube.com/watch?v=hTWKbfoikeg

Quality and Formats

Use the option -F to list all available formats:

$ youtube-dl -F https://www.youtube.com/watch?v=hTWKbfoikeg
[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)

As you can see, YouTube stores video files in different formats and resolutions.

To download a file an a preferred format, use the option -f with the format code.

The format code can be taken from the output of the above 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 https://www.youtube.com/watch?v=hTWKbfoikeg

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>

For example, to download the entire YouTube channel of the user NirvanaVEVO, run:

$ youtube-dl -citw ytuser:NirvanaVEVO

Cool Tip: Download is too slow? Test the Internet speed from the Linux command line! Really easy! Read more →

Download All YouTube Videos From a PlayList

Download all YouTube videos from some playlist:

$ youtube-dl -citw <PLAYLIST URL>

For example, to download all YouTube videos from the playlist Nirvana, run:

$ youtube-dl -citw https://www.youtube.com/playlist?list=PL71D5FDBC8F7CA3B8

Read man to learn more about youtube-dl:

$ man youtube-dl
Was it useful? Share this post with the world!

6 Replies to “Download YouTube Video – Linux Command Line”

  1. Круто мэн,всё просто и понятно и Нирвану я сам обожаю!Спасибо большое за такой ресурс.

  2. Уже не актульно. Похоже youtube прикрыл возможность такого скачивания.

    1. Смею несогласиться:

      $ youtube-dl https://www.youtube.com/watch?v=hTWKbfoikeg
      [youtube] hTWKbfoikeg: Downloading webpage
      [youtube] hTWKbfoikeg: Downloading video info webpage
      [youtube] hTWKbfoikeg: Extracting video information
      [youtube] hTWKbfoikeg: Downloading js player vfl1RKjMF
      [youtube] hTWKbfoikeg: Downloading js player vfl1RKjMF
      [youtube] hTWKbfoikeg: Downloading MPD manifest
      [download] Destination: Nirvana - Smells Like Teen Spirit-hTWKbfoikeg.webm
      [download] 100% of 22.20MiB in 00:02
      
  3. thank you. is there any way, other than closing the terminal, to stop an initiated download?

    1. press ctrl+c

  4. Omidiji Rasheed says: Reply

    Thanks for the detailed information. Please how can one locate the file location after a successful download?
    I already checked the folder location from preference configuration and others.

Leave a Reply