We all love listening to music. Whether it’s in the gym, at work, outside, music is part of our life. Everyone has their own music collection and undoubtedly everyone likes to expand it. While there are streaming services such as Spotify, many people still like downloading their own music and organizing their albums and playlists.

Today we are going to show you how to easily download mp3 tracks from YouTube videos. To complete this, we will be using YouTube-DL – a command line video download tool for Linux. Based on python, youtube-dl can be used on almost all (if not all) Linux distributions. If you haven’t heard about this tool already, I urge you to check our detailed review of youtube-dl in the link below:
Don’t Miss: Install YouTube-DL – A Command Line Video Download Tool for Linux
In this tutorial you will learn how to download mp3 tracks from Youtube using youtube-dl tool. Of course, first you will need to have it installed on your system. If you haven’t checked the above article yet, here is how to install it:
Install YouTube-DL – A Youtube Video Downloader for Linux
YouTube-DL is available for both CentOS/RHEL/Fedora and Ubuntu/Debian/ derivatives and it can be easily installed by using the following commands:
$ 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
Download MP3 Track from Youtube Video in Linux
Youtube-dl has quite an extensive "help"
page and if you want to review it, simply type:
# youtube-dl --help

If you are looking for a specific option, I recommend using the “grep” utility and search for specific word as shown.
# youtube-dl --help | grep extract-audio

Now to download a video as mp3 track, we need the following two options:
--extract-audio
(short option -x) – Convert video files to audio-only files.--audio-formatÂ
– specifies the audio format in which the file will be downloaded. The supported audio formats are “best”, “aac”, “vorbis”, “mp3”, “m4a”, “opus”, or “wav”; “best” is set by default
To download a video as mp3 file, you can use one of the following commands:
# youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=jwD4AEVBL6Q

If you want to have a cover art for the mp3 file, you can add the --embed-thumbnail
option:
In that case the command will look like this:
# youtube-dl -x --embed-thumbnail --audio-format mp3 https://www.youtube.com/watch?v=jwD4AEVBL6Q

Download Multiple MP3 Tracks from YouTube Playlist
As you probably noticed, youtube playlists are getting more and more popular lately. So the chances are that you will want to download more than one track from a playlist. Luckily youtube-dl provides an option to download a whole playlist or just a range of songs within it.
For that purpose, you will need to use the following options:
--playlist-start NUMBER
– Playlist video to start at (default is 1)--playlist-end NUMBER
– Playlist video to end at (default is last)
Where "NUMBER"
is the starting and ending point of the playlist. The command below will download the first 5 songs from the given playlist:
#Â youtube-dl -x --audio-format mp3 --playlist-start 1 --playlist-end 5 https://www.youtube.com/playlist?list=PL9LUD5Kp855InMnKTaRy3LH3kTIYJyBzs

If you prefer to download the whole playlist, don’t use the playlist-start and playlist-end parameters. Instead, simply pass the playlist URL.
Download MP3 Tracks from Different YouTube Playlist
We also know that you may not like all the songs in other people’s playlists. So what if you want to download many songs from different playlists? Well a workaround on that matter is to get a list of URLs in a single file.
Write the URLs in a file called videos.txt
and make sure to keep one URL at a line. Then you can use the following "for"
loop to download the songs:
# for i in $(<videos.txt); do youtube-dl -x --audio-format mp3 $i; done

The above is a simple solution to download multiple songs from different Youtube URLs.
Conclusion
Youtube-dl is a simple, yet powerful tool that can help you to download music on your devices. You are now ready to expand your music libraries to a whole new level.
If you have any questions or comments, please do not hesitate to submit them in the comment section below.
Today I used the following command:
# youtube-dl --embed- thumbnail --write-- thumbnail -x audio -format mp3 ((URL)- | youtube-dl --write-sub (URL)
youtube-dl downloaded two files one audio & one video file is this wrong?
The WonderFox free hd I am using is a very good YouTube downloader and converter that makes it easy to download the music we want from YouTube and convert it to MP3 format. You can have a try!
Quick question, can this program include an id3tag in the mp3 file?
Great article and great tool! I use it almost every day. A pair of things that would be nice to add to your article would be how to provide a proxy to youtube-dl and youtube-dl taking links to download from a text file. Thx!
I believe you are not allowed to save the soundtracks from songs as you won’t have a legal license and thus are infringing the content owners copyright.
You should at least mention that in the article.
You wouldn’t like it if someone ripped all your website content and posted it online so they could read it without the adverts as you would say you are losing income.
Don’t be a d*ck.
You might want to include the information on how to select or permanently set up a specific folder/path to download the file vs the home folder as the default location.
Maybe link to the youtube-dl FAQ https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-put-downloads-into-a-specific-folder
or
alter the information in the link in favor of the music folder as this specific article is about making them into mp3s.
Thank you for your suggestion Alfredo. Actually since there was quite an interest towards this article, I am thinking about either updating this one or writing a new one with a script that will allow you to easily manage your downloads, without passing this many parameters each time you download a track.
Hey Jeff. I understand your concern. It looks like the full source is available for download. Look here:
http://rg3.github.io/youtube-dl/download.html
If it helps, I have been using the youtube-dl script since Tecmint put out the original article in September with no weird side effects. (Running Linux Mint which is an Ubuntu variant.)
Chris
There are lot of Firefox extensions available. You can install one of them and download video and mp3, while you are watching them in Firefox. So No need to use YouTube.dl
Hello Jeff,
You don’t need to put the binary file in /usr/local/bin/. You can download it as regular user on your machine and place it in a directory by your choice from where you will access the file later. For example you can do:
wget https://yt-dl.org/downloads/latest/youtube-dl -O /home/tecmint/
And then run the file from /home/tecmint/
If you are interested in reviewing the documentation about youtube-dl, you can check the following link:
https://rg3.github.io/youtube-dl/
You’re ask us to use our root privileges to install a binary in a system executable directory without the source code? How do we know that this isn’t malware of some kind, or a social engineering attack?
I would really love to be able to do what you are doing, but without the source code, I’m not going to put it in a system directory.
Maybe on a virtual machine or on a chroot’d machine.
Source can be found here: https://github.com/rg3/youtube-dl
@Jeff Silverman
Great security concern there, may be you can check the source code out, i have used this program and i do not think from my assessment that it has any security concerns yet.
But who knows, issues such as the one you have raised have to be put into great consideration.
@Marin Todorov
Thanks for the great article
Apologies I didn’t have the time to provide the link to the source code of the application. I see that Josh already did that for me :)
Still, I haven’t heard for any problems with youtube-dl, but you may always download it to a different location if you don’t like the one provided in the article.