Is it possible to download Youtube video from Linux terminal?
Of course, anything is possible in Linux World. There are talented people around who develop such good tools and youtube-dl is one of them using which you can download youtube videos from Linux Terminal.
What is Youtube-dl?
youtube-dl is a command-line program to download videos from YouTube and a few more sites. It is a Python-based tool, so you need an python interpreter installed on the system. Another thing to say about the application is that it is not built for any specific system. This is positive because you can use it on Windows, Linux, macOS and so on.
It is released to the public domain, which means you can modify, redistribute or use it however you like. If you have profound knowledge of programming and Python, then without too much trouble you can modify it as per your needs.
Below are some of the features of youtube-dl,
- Download videos in up to 4K
- Simultaneously, you can download entire playlists
- You can resume downloading if at any time the application stops running
- Supports download limiting, ideal if you want to save bandwidth
- You can also download subtitles
But not only that, there are also many more features included such as post-processing of the download where you can enhance the audio or the use of proxy.
Install youtube-dl on Linux
There are several methods to install youtube-dl, you can download binary from official site, use distribution package repository or snap package of youtube-dl. Linux developer you can even compile source code as well.
Method 1: Install using the Linux distribution’s official repositories
The youtube-dl is present in some of the Linux distributions. In the case of Debian-based distributions like Ubuntu, Linux Mint , run
sudo apt update sudo apt install youtube-dl
sudo dnf install youtube-dl
and if you are using Arch Linux or a derivative like Manjaro, then the command
sudo pacman -S youtube-dl
to get youtube-dl.
Verify the installed version with the following command
Although, it is easy method, but you may end up getting outdated version of the application. You can use other methods mentioned below to get latest version of youtube-dl application.
Method 2: Getting the latest version of youtube-dl
The best way is to get the latest version of the tool directly. For this, you can use the Linux terminal.
First, open terminal and download yuotube-dl to a directory in the PATH such as
/usr/local/bin/ using the wget command
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
a nd then, assign the correct permissions to the application using
sudo chmod a+rx /usr/local/bin/youtube-dl
This way, you will be able to use the latest stable version of the yuotube-dl application.
Method 3: Using PIP: the package manager for Python
youtube-dl is a Python application, so you can easily install it using PIP.
sudo -H pip3 install youtube-dl
It’s that simple.
Download videos from YouTube using youtube-dl
The most basic way in which you can download a video using the tool is as follows
It will then download and save to the directory where you ran the command line.
But in what quality will it download? Well, it will automatically find the best format, but as you know there are many. To show you which are the available formats, you will have to run.
youtube-dl -F [video_url]
You will see an output screen like this
Available formats: 37 : mp4 [1080x1920] 46 : webm [1080x1920] 22 : mp4 [720x1280] 45 : webm [720x1280] 35 : flv [480x854] 44 : webm [480x854] 34 : flv [360x640] 18 : mp4 [360x640] 43 : webm [360x640] 5 : flv [240x400] 17 : mp4 [144x176]
When you know which format to download, then run something like this
youtube-dl -f [number] [video_url]
But what if you just want the audio from the video? Well, for that, there is the
youtube-dl -x [video_url]
You can even process it in one go, e.g., save it in MP3 format.
youtube-dl -x --audio-format mp3 [video_url]
But the truth is that youtube-dl has plenty of options and settings that you should read in its documentation.
Uninstall youtube-dl from the system
If you don’t want it on your system anymore, you can remove it from your system.
In case you have installed it using the official repositories of each distribution, then you can uninstall it from there.
For Debian, Ubuntu and derivatives
sudo apt remove youtube-dl
sudo dnf remove youtube-dl
And for Arch Linux
sudo pacman -R youtube-dl
Now, if you downloaded the youtube-dl binary, you just need to remove it
sudo rm /usr/local/bin/youtube-dl
Lastly, in the case of PIP, you just need to run
sudo pip3 uninstall youtube-dl
This way, it will no longer be on the system.
YouTube is the largest collection of videos in the world, and it is normal that we want to download some of them for different purposes. Now you can do it from the terminal with youtube-dl.
I hope you liked this post and that you can share it with us, so we can keep growing.