Install Youtube-dl on Linux and How to Use it

Youtube-dl is a fantastic tool for downloading videos. I use it nearly everyday to download my favourite channel videos, playlists etc from youtube.com.

Hint: If YouTube is blocked in your country or area, you can set up your own VPN server or proxy server to unblock it.

Install Youtube-dl on Linux from Python

You can install youtube-dl on Linux from python package repository. First you need to install the python package manager – pip.

Debian/Ubuntu:     sudo apt install python-pip

CentOS:            sudo yum install python-pip

Fedora:            sudo dnf install python-pip

Arch Linux:        sudo pacman install python-pip

OpenSUSE:          sudo zypper install python-pip

Then install youtube-dl with pip:

sudo pip install youtube-dl

Now the installation is completed.

Do Not Install it From Software Repository

If you are using Linux, then you can also install youtube-dl from your distribution’s repository. For example to install it on Debian/Ubuntu systems, just issue the following command:

sudo apt-get install youtube-dl

But I recommend the first method because the version from the repository is often not the latest. You might get some error when using youtube-dl if you choose to install it from repository.

Update or Remove YouTube-dl

Sometimes youtube-dl can’t download videos. For example, it can’t find any videos in a playlist, you can try upgrading to the latest stable version. Use the following command to update:

sudo pip install --upgrade youtube-dl

Use this command to remove it from your OS:

sudo pip uninstall youtube-dl

Unable to Extract Title Error

If you encounter the “unable to extract title error”, then you need to reinstall or upgrade youtube-dl.

How to Download Videos From Youtube

To download a single video, just type youtube-dl in the terminal followed by the video URL. For instance:

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

To download a playlist, just append the playlist URL to youtube-dl, like this:

youtube-dl https://www.youtube.com/playlist?list=PLCGm32c1bz2qw8OrqqIgn-27-DapsiSJS

To download all videos from a user, type the following in the terminal:

youtube-dl -ciw ytuser:username

You can find the username when you go to the user’s channel page and then click the videos button.

youtube-user

Now you can see the userid in the address bar of your browser.

youtube-userid

Also, you can append the user’s YouTube URL to download all of the user’s videos.

youtube-dl -ciw https://www.youtube.com/user/username

If you aren’t a native English speaker, you might want to download and embed subtitles in the videos.

youtube-dl -ciw --write-auto-sub --embed-subs https://www.youtube.com/user/username

You need to install ffmpeg for this to work.

sudo apt install ffmpeg

Download an Entire Channel

Just append the channel’s URL.

youtube-dl -ciw https://www.youtube.com/channle/channelname

Download behind a Proxy

You can use the --proxy option to specify HTTP/HTTPS/SOCKS proxy like below.

youtube-dl --proxy socks5://127.0.0.1:1080/ https://www.youtube.com/videourl

Download Audio Books From YouTube

If you are going to download audiobooks from YouTube, but you only want the audio, not the video, so you can save disk space. Then you can use the -x option to convert video files to audio-only files.

youtube-dl -ciwx https://www.youtube.com/user/GreatestAudioBooks

You need to install ffmpeg for this to work.

sudo apt install ffmpeg

You can also specify the audio format and audio quality. By default, the video files can be converted to .opus files, which your software might not be able to play. You can tell YouTube-DL to convert video files to mp3 format and use the highest quality (0).

youtube-dl -ciwx --audio-format mp3 --audio-quality 0 https://www.youtube.com/user/GreatestAudioBooks

Playing Video/Audio Files in the iOS VLC Player

The VLC player can play all kinds of audio/video file without problems, including .opus, .mp3, .aac, .mp4, .mkv files. However, I found that if the file name includes emoji characters, then the VLC player on iOS may not be able to recognize the file.

VLC player on iOS can correctly display the embedded subtitles, just like how it’s displayed on YouTube. However, the VLC player on my Linux desktop also displays the timestamps in the subtitle, which isn’t useful at all. The MPV media player on Linux desktop can display embedded subtitles correctly.

sudo apt install mpv

Wrapping Up

I hope this tutorial helped you install and use YouTube-DL to download videos from YouTube. That’s it. Enjoy!

Rate this tutorial
[Total: 6 Average: 5]

2 Responses to “Install Youtube-dl on Linux and How to Use it

  • Looks like the pip command is incorrect; should be `pip install youtube_dl` and NOT `pip install youtube-dl`.

  • sudo pip install youtube-dl not sudo pip install youtue-dl beginning

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here