The download and install instructions for youtube-dl are here.
As a quick note, on Mac you can run:
brew install youtube-dl
And on GNU/Linux:
sudo curl https://yt-dl.org/downloads/2015.11.27.1/youtube-dl -o /usr/local/bin/youtube-dl sudo chmod a+rx /usr/local/bin/youtube-dl
For NixOS fans, it's available via nix-env.
Many Linux distros come with FFmpeg installed I believe.
If not, you can use your distros package manager. For example, on Ubuntu:
sudo apt-get install ffmpeg
In some older versions of Ubuntu (and probably other distros), you should use avconv instead of ffmpeg. AVConv was simply a fork of FFmpeg and the two projects have subsequently been merged back into FFmpeg again.
On Mac you can use homebrew:
brew install ffmpeg
Downloading the video
To download a Youtube video, you simply run the following line (making sure to replace the URL with the one of the video you want to download):
Converting video to mp3
To now convert the mp4 video to mp3, you can use FFmpeg (comes standard with most Linux distros I believe).
ffmpeg -i Rick\ Astley\ -\ Never\ Gonna\ Give\ You\ Up\ \[HQ\]-DLzxrzFCyOs.mp4 Rick\ Astley\ -\ Never\ Gonna\ Give\ You\ Up.mp3