Download video from YouTube and convert it to mp3 in Linux

To download video from YouTube you can use some site in Internet, but many of them have ads, viruses and don’t do what you need.

But you can use simple program youtube-dl. It is free, open source, work in console and can download video, audio from YouTube in one click.

To install youtube-dl use simple commands:

1. Install python:

sudo apt install python3
sudo ln -s /usr/bin/python3 /usr/local/bin/python

2. Install youtube-dl:

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

How to use youtube-dl:

To get all supported formats from YouTube video use command:

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

Thic sommand show you all video formats and id’s

To download some format use flag -f and ID from previous command:

youtube-dl -f 18 https://www.youtube.com/watch?v=QpqdtB4ssX0

That’s all, video starts download. You can use it in terminal and don’t need to open suspicious sites.

You can also download playlists of video from YouTube the same way.

Convert video to mp3 audio.

And you can convert video to mp3 using program ffmpeg. To install ffmpeg use command:

sudo apt install ffmpeg

To convert video to mp3 use command:

ffmpeg -i video.mp4 -acodec libmp3lame audio.mp3