5

I am having no luck getting youtube-dl installed on my 20.04 system. Here's what I have tried:

  1. sudo apt-get install youtube-dl

    RESULT: The command executes OK, but when I try to download anything I get errors. I checked the version:

    $ youtube-dl --version
    2020.03.24
    $ which youtube-dl
    /usr/local/bin/youtube-dl
    

    I assume I got an old version of youtube-dl because Ubuntu's repo is out-of-date?

So, searching for solutions led me to try this:

  1. pip3 install --upgrade youtube-dl

    This attempt being a highly up-voted answer here on SE.. But first - removed the apt-installation using sudo apt-get remove youtube-dl

    But when I check to verify the version, I remain stuck at the old version!

    $ youtube-dl --version
    2020.03.24
    

    So let's move that out before trying something else:

    $ pip3 uninstall youtube-dl
    Found existing installation: youtube-dl 2020.11.26
    Uninstalling youtube-dl-2020.11.26:
      Would remove:
        /home/walker/.local/etc/bash_completion.d/youtube-dl.bash-completion
        /home/walker/.local/etc/fish/completions/youtube-dl.fish
        /home/walker/.local/lib/python3.8/site-packages/youtube_dl-2020.11.26.dist-info/*
        /home/walker/.local/lib/python3.8/site-packages/youtube_dl/*
        /home/walker/.local/share/doc/youtube_dl/README.txt
        /home/walker/.local/share/man/man1/youtube-dl.1
    Proceed (y/n)? y
      Successfully uninstalled youtube-dl-2020.11.26
    

    Whoa!? I just un-installed the current version!

  2. sudo snap install youtube-dl

    Aka "Method 2" from this website, which went as follows:

    $ sudo snap install youtube-dl
    youtube-dl 2020.11.17+gitd65d891 from Joe Borg (joeborg) installed
    $ youtube-dl --version
    bash: /usr/bin/youtube-dl: No such file or directory
    $ which youtube-dl
    /usr/local/bin/youtube-dl
    

Which leaves me confused and bewildered beyond repair. I have used youtube-dl for over a year now & installed on macOS & Debian systems - with no problems. I know Ubuntu is different, but... this is confusing.

How do I fix this?

muru
  • 207,228
deWalker
  • 401

2 Answers2

9

If you install the youtube-dl package from the 20.04 Ubuntu archive, it does not result in any /usr/local/bin/youtube-dl file. So probably you have previously installed youtube-dl in some other way than one of the ways you mention in your question, and that may be the cause of the confusion.

If you don't remember how that happened, I would suggest that you simply delete that file:

sudo rm /usr/local/bin/youtube-dl

The pip3 way is a good way to get the latest available version. Please note though, that if you install via pip3 as your own user (i.e. without sudo) the youtube-dl executable will end up in $HOME/.local/bin, and you may need to log out and log in again to make that directory be included in PATH.

3

An alternative solution:

Background:

There are installation instructions on yt-dl's GitHub site that effectively download a copy of the latest version of youtube-dl to /usr/local/bin - they are simple enough even I could follow them.

But that leads to another problem - possibly an Ubuntu problem, a Python problem or a youtube-dl problem... I don't know whose problem it is, but here's the problem. After following the yt-dl installation instructions, try to check the version:

$ youtube-dl --version
/usr/bin/env: ‘python’: No such file or directory

As I understand this, it just means that the system (Ubuntu) and youtube-dl cannot resolve where Python is installed. But I know I do have Python3 installed:

$ which python
$ which python3
/usr/bin/python3

And since I did not install Python3, this seems to mean that Ubuntu 20.04 came with Python3 installed, but Python(2) was not installed.

Solution 1:

$ sudo apt-get install python-is-python3

Check/verify solution:

$ youtube-dl --version
2020.11.29

So this has been tested & verified on my system - FWIW.

Solution 2:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode

Verify this works (after removing the previous solution 1):

$ youtube-dl --version
2020.11.29

Credits to @mighty9245 for this solution.

Addendum:

Personally, this manual installation solution works best for me as I have no interest in becoming entangled in all of the Pythonic minutae; virtual environments and other artifacts. And while it's disappointing that Ubuntu's repo can do no better than a version of youtube-dl that's 8 months old, this installation procedure does have one advantage over the apt repo:

A manual installation of youtube-dl allows one to update directly and immediately via:
sudo youtube-dl -U.


From the Focal Fossa Release Notes:

Python3 by default

In 20.04 LTS, the python included in the base system is Python 3.8. Python 2.7 has been moved to universe and is not included by default in any new installs.

Remaining packages in Ubuntu which require Python 2.7 have been updated to use /usr/bin/python2 as their interpreter, and /usr/bin/python is not present by default on any new installs. etc, etc

deWalker
  • 401