×


Download YouTube Videos on Ubuntu Linux - How to do it ?

For many reasons, you might want to download a video to save for later or to play offline. The youtube-dl is a free and open-source utility that lets you download YouTube and other videos from the Linux command line. 

It not only works for Linux but also for Windows and MacOS. 

Among many other utilities, youtube-dl has a large set of features and its updates are released more frequently.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Software Installation tasks on Ubuntu system.

In this context, we shall look into how to install the youtube-dl utility and use it to download YouTube videos through the command line in Linux.


Main feature of youtube-dl utility:

1. Supported on Linux, Windows, and MacOS.

2. Download videos in particular quality and format.

3. Other than just YouTube, it supports downloading videos from many sites  .

4. Download subtitles of videos.

5. Set maximum download rate in bytes per sec.

6. Download only audio from a video.

7. Download video in specific format and quality.


How to install youtube-dl on Ubuntu ?

The youtube-dl is an open-source python script. 

We will download this script and save it in the /usr/local/bin. Here is the command to do so:

$ sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl

Now using the following command, make the script executable:

$ sudo chmod a+rx /usr/local/bin/youtube-dl

Now the youtube-dl latest version has been installed on your system. 

To view what version has been installed, use the following command:

$ youtube-dl --version


How to update youtube-dl on Linux ?

The youtube-dl releases its updates once a month or a week. 

To update your youtube-dl version, use the following command:

$ youtube-dl -U


How to install youtube-dl via snap on Linux ?

The youtube-dl is also available as a snap package. To install youtube-dl snap, first enable snapd on your system. Use the following command to do so:

$ sudo apt install snapd

Then to install youtube-dl, use the following command:

$ sudo snap install youtube-dl


How to Download YouTube videos on Linux ?

To download a YouTube or any other video via youtube-dl, use the following syntax:

$ youtube-dl <video_url>

Replace <video_url> with the URL of the required video.

The downloaded video will be saved as 'title-id.ext' in the current directory.

For Example:

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


How to Save the video in a different location ?

By default, youtube-dl saves the downloaded video in the current Terminal directory. You can also save the file in a different location while keeping the original video name format. 

For example, to download the video in /home/user/Videos directory, use the following syntax and replace <video_url> with actual URL:

$ youtube-dl -o ‘~/Videos/%(title)s-%(id)s.%(ext)s’ <video_url>


How to Save the video with a different name ?

You can save the file with a different name other than the original name:

$ youtube-dl -o '<filename>' <video_url>

Example:

$ youtube-dl -o 'UP.mp4' https://www.youtube.com/watch?v=Rm3ZKdNuvjI

The downloaded video will be saved as 'UP.mp4' in the current directory.


You can also include custom details in the filename, such as release date, uploader name, channel name, etc. This can be done using the -o option. 

The -o option allows you to specify a template  for the file names. For example, the following command will download a YouTube video and include title, upload date, and video duration in the filename:

$ youtube-dl -o '%(title)s.%(upload_date)s.%( duration)s' https://www.youtube.com/watch?v=Rm3ZKdNuvjI


How to Download multiple videos ?

Sometimes, we need to download multiple videos. Instead of running the download command for all videos one by one, you can download all of them with a single command. To do so, list the URLs of all the videos in a file, one URL per line, and then call that file using the -a option. 

Here is the command syntax to download multiple videos:

$ youtube-dl -a <file-name>

Where <file-name> is the file containing all the URLs.

This command will extract the audio from the specified video and save it in the current directory.

This command will download all the URLs specified in the file and save them in the current directory.


How to Download only audio from a video ?

If you need to download only audio from a video, use the -x option as follows:

$ youtube-dl -x <video-url>

This command will extract the audio from the specified URL and save it in the current directory.


How to Download video in specific format and quality ?

Using youtube-dl, you can also download a video in a specific format and quality. You can list the available formats of a specific video using the following command:

$ youtube-dl -F <video_url>

Now from the list, you can choose to download a specific format and quality using the format code:

$ youtube-dl -f <format code> <video_url>


How to Uninstall youtube-dl from Ubuntu Linux ?

You can also remove youtube-dl from your system if you need to do so. As we have installed youtube-dl by downloading its script in the system path /usr/local/bin. So now in order to remove youtube-dl, you will need to remove the script from the path as follows:

$ sudo rm -rf /usr/local/bin/youtube-dl

If you have installed youtube-dl via snap, you can remove it as follows:

$ sudo snap remove youtube-dl


[Need urgent assistance in installing Software on Ubuntu? We are available to help you. ]


Conclusion

This article covers how you can download YouTube videos on Linux using the youtube-dl utility. The youtube-dl is a handy utility with a large feature set. However, there is a lot more you can do with this utility. To explore more features, visit its official documentation . To play the downloaded videos, you can use any media players like VLC , FFmpeg , and so on.

youtube-dl is a command-line program that lets you easily download videos and audio from more than a thousand websites. 


youtube-dl is a Python based small command-line tool that allows to download videos from YouTube.com, Dailymotion, Google Video, Photobucket, Facebook, Yahoo, Metacafe, Depositfiles and few more similar sites. 

It written in pygtk and requires Python interpreter to run this program, it's not platform restricted. It should run on any Unix, Windows or in Mac OS X based systems.


To Install YouTube-DL in RHEL/CentOS and Fedora:

The youtube-dl program can be installed by enabling epel repository under your systems. Once enabled, you can install using 'yum' package manager tool:

$ yum install youtube-dl

Also, if you wish to add any third party repository, you can still install it right away using curl or wget command:

$ curl https://yt-dl.org/latest/youtube-dl -o /usr/local/bin/youtube-dl

OR

$ wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl

Your system must have curl or wget packages installed to fetch the recent version youtube-dl file. If you don't have them, you may yum to get it.

After fetching the file, you need to set a executable permission on the script to execute properly:

$ chmod a+rx /usr/local/bin/youtube-dl


To Install YouTube-DL in Ubuntu/Linux Mint and Debian:

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-get update
$ sudo apt-get install youtube-dl

Also, instead using any third party PPA, you can use curl or wget command to install latest version of youtube-dl script:

$ sudo curl https://yt-dl.org/latest/youtube-dl -o /usr/local/bin/youtube-dl

OR

$ sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl

After downloading the script, set the executable permission:

$ sudo chmod a+rx /usr/local/bin/youtube-dl


To Update YouTube-DL,

Youtube-dl itself can be updated to the latest version using the following command:

$ youtube-dl -U