I spend a lot of my time on YouTube, looking up topic that interest me, or trying to learn how to do something, etc. Sometimes, I want to be able to have a copy of the video to watch offline. That’s where youtube-dl comes in.

To install youtube-dl on Linux, you would simply run the following command:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl && sudo chmod a+rx /usr/local/bin/youtube-dl

Other download instructions can be found at https://ytdl-org.github.io/youtube-dl/download.html

Once you have youtube-dl, you can keep it up to date by running

sudo youtube-dl -U

youtube-dl is pretty powerful, and is also not only limited to youtube, it allows you to download videos from many websites in many formats. And if you also have ffmpeg installed, it can do conversions and join downloaded parts into containers.

I have an alias on my system to allow me to quickly download a 1080p video from youtube:

alias yt1080='youtube-dl -f "bestvideo[height<=1080]+bestaudio" --merge-output-format mkv --prefer-free-formats -i --output "%(title)s.%(ext)s" --write-sub --sub-lang EN --sub-format SRT --add-metadata ' 

Put this into a file in your home directory called .bash_aliases and then run

. ~/.bashrc

You should then be able to type yt1080 in your terminal to download any video on YouTube.

For instance:

yt1080 https://www.youtube.com/watch?v=dQw4w9WgXcQ

You will now have a locally-downloaded copy of the YouTube video to do with as you wish. This is very handy for archiving YouTube channels, or for being able to watch your favorite tutorial vids offline.