Install youtube-dl from the Ubuntu official repository:
sudo apt install youtube-dl
or, as suggested by the official readme, use curl or wget. This will allow you to upgrade using sudo youtube-dl -U.
To download a video, run the following command:
youtube-dl <url>
E.g
youtube-dl http://www.youtube.com/watch?v=_z-hEyVQDRA
You can also specify other options -b Best quality -m Mobile version -d High Definition -g Don’t download, just show the url -c Resume download of a video which was interrupted before -w Don’t overwrite existing file
For a complete list of switches execute man youtube-dl in the terminal.
Download as MP3
You can download the mp3 directly from YouTube without using ffmpeg to convert it.
youtube-dl --extract-audio --audio-format mp3 <url>
From the online help:
-x, --extract-audio convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)
Using youtube-dl -h, you can see additional options for retaining the original video, adjusting the bitrate or quality of the audio, and a few others.
MediaHuman
For those of us who prefer a GUI interface, there is YouTube to MP3 from MediaHuman.
Direct downloads are available for Ubuntu 16.04+, but I prefer the repository because of automatic updates.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7D19F1F3 sudo add-apt-repository https://www.mediahuman.com/packages/ubuntu sudo apt update sudo apt install youtube-to-mp3
Using the dash or another launcher, search for and open ‘Youtube to MP3’. Copy the YouTube video URL from the browser to your clipboard and paste it into the application by clicking the ‘Paste link’ button in the top-left corner. See the screenshot below.
The download and conversion will begin automatically, and the audio will be saved in the Home folder under ~/Music/MediaHuman Downloaded.