2018-04-08 [updated 2020-07-12]

There’s a handy program for downloading YouTube videos that works straight on the command line called youtube-dl. It can be installed on Linux or Macintosh and only requires Python, which you probably already have.

Install youtube-dl with two simple commands in the terminal:

sudo curl -L -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

You’ll want to create a config file for youtube-dl which tells it where to download the video files to. I believe it downloads files to the same directory as the youtube-dl binary if you don’t specify a destination. Download this config file to your Desktop and then run the following command to move it to the right location in the file system for youtube-dl to find it:

mkdir ~/.config/youtube-dl
mv ~/Desktop/config.txt ~/.config/youtube-dl/config

You should now be able to download any YouTube video (to the Desktop) by its URL with the following command in terminal (but replace the URL with the one you actually want):

youtube-dl ""

If you want to download several videos you can create a batch file. The batch file is a text file containing one URL per line. Here is an example batch.txt file. Feel free to download it, modify it, re-use it. With the batch file (batch.txt) on the Desktop you can tell youtube-dl to download every video in the batch file with the following command:

youtube-dl -a ~/Desktop/batch.txt

You can use youtube-dl to download videos not only from YouTube but many other supported sites. Keep youtube-dl updated with the following command:

sudo youtube-dl -U

If you’re running youtube-dl on a remote server that you’re accessing over ssh and you want to download a batch of videos without needing to keep the ssh session active try this command, then close the terminal window:

nohup youtube-dl -a batch.txt &> /dev/null &

It’s a super powerful tool. To learn more about youtube-dl type:

youtube-dl --help