Downloading YouTube videos from the Linux terminal can be a daunting task for beginners. However, with the right tools and techniques, you can easily download your favorite videos for offline viewing. In this article, we will share some tips and tricks for downloading YouTube videos in the Linux terminal.
Before you can download YouTube playlists, you need to install the youtube-dl tool. You can install youtube-dl using one of the following options:
The Recommended Way
To install it right away for all UNIX users (Linux, macOS, etc.), type:
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
If you do not have curl, you can alternatively use wget:
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
Installing Youtube-dl from Official Repositories
- On Ubuntu, Debian, and LinuxMint macchine:
sudo apt update && sudo apt install youtube-dl
- CentOS/RHEL 7/6 and Scientific Linux
sudo yum install youtube-dl
- CentOS/RHEL 8, CentOS Stream 9 and Fedora
sudo dnf install youtube-dl
Once the installed is finished successfully, You can download any YouTube videos directly from the Linux terminal.
Use youtube-dl with the -o option
The youtube-dl tool is a popular command-line utility for downloading YouTube videos in the Linux terminal. One useful option is the
-o option, which allows you to specify the output file name and location. For example, to download a YouTube video and save it to the ~/Downloads folder with the filename myvideo.mp4, use the following command:
youtube-dl -o '~/Downloads/myvideo.mp4' <video URL>
Download videos in different resolutions
YouTube videos are available in different resolutions, from 240p to 4K. If you have a slow internet connection or limited storage space, you may prefer to download videos in lower resolutions. The youtube-dl tool supports the
-f option, which allows you to specify the video format and resolution. For example, to download a YouTube video in 360p resolution, use the following command:
youtube-dl -f 18 <video URL>
Download videos in batches
If you want to download multiple YouTube videos at once, you can use the youtube-dl tool with the
-a option, which allows you to read a list of video URLs from a file. Create a file with one video URL per line and use the following command to download all the videos:
youtube-dl -a <filename>
Use a download manager
If you have a slow internet connection or want to pause and resume downloads, you can use a download manager such as aria2c. Aria2c is a command-line utility that supports multi-threaded downloads and resumable downloads. To use aria2c with youtube-dl, use the following command:
youtube-dl -o - <video URL> | aria2c -c -i -
Download videos with subtitles
YouTube videos are available in different languages, and some videos come with subtitles. If you want to download a YouTube video along with its subtitles, use the following command:
youtube-dl --write-sub --sub-lang <language code> <video URL>
Download Audio Only
You can simply download audio of any video on your system in mp3 formats, like following commands.
youtube-dl --extract-audio --audio-format mp3 <video URL> -o audio.mp3
Download the YouTube playlist
To download a YouTube playlist, you need to find the playlist URL. You can find the playlist URL by navigating to the playlist on YouTube and copying the URL from the address bar.
To download a YouTube playlist, use the following command:
youtube-dl -i -f best -o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' <playlist URL>
Here’s what each option in the command does:
-i: ignore errors and continue downloading
-f best: download the best available quality
-o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s': specify the output format for downloaded files, including the playlist name, index, title, and file extension
: replace with the URL of the YouTube playlist you want to download
Once you execute the command, youtube-dl will download each video in the playlist and save it to a folder with the same name as the playlist. Each video will be named with its index number, title, and file extension.
Downloading YouTube videos in the Linux terminal can be a breeze with the right tools and techniques. In this article, we shared some tips and tricks for using youtube-dl and other command-line utilities to download YouTube videos in different resolutions, download videos in batches, use a download manager, and download videos with subtitles. Use these tips to enhance your video downloading experience in the Linux terminal.