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
  • 197,895
  • 55
  • 485
  • 740
deWalker
  • 391
  • youtube-dl is a 'universe' or Community Supported package. It gets updated only when a user detects issues, and files a bug on it (I've done it in the past, usually it's fixed within a day or two, but it'll depend on the volunteers time availability). My own Ubuntu has 2020.11.21.1 according to youtube-dl --version installed, but I'm not on focal. In your case I'd file a bug (ie. request to update).. but it's up to you (updates occur regularly due to google's constant changes). – guiverc Nov 29 '20 at 01:36
  • 1
    Refer to Gunnar's answer. That is faster, and doesn't require the bug report, plus consequential re-packaging work for the community member (volunteer) who packages it in their own time.. I've done that too on many older releases – guiverc Nov 29 '20 at 01:58
  • alternative that , alas , uses a third party in your browser is loader.to. works for bitchute, brandnewtube etc – pierrely Dec 01 '20 at 05:24

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.

Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94
  • That did it - thank you! I don't ordinarily use pip3 as I don't use Python, and have some ugly scars :) from previous experiences. I prefer to use the trusted apt tools. I wonder why Ubuntu doesn't maintain a current version of youtube-dl in their repo?, but I will guess that's asking or an opinion. In retrospect, I think I should have installed the source files & built it myself so that I could use youtube-dl -U for upgrades. Anyway - thanks again. – deWalker Nov 29 '20 at 02:28
  • I tried to upvote, but wasn't allowed to do so. I'll try to remember to come back & do that - if I ever get 15 rep :) – deWalker Nov 29 '20 at 02:32
  • 3
    @deWalker: As guiverc pointed out in a comment, the package is maintained by a volunteer. I would rather ask: Why is youtube-dl in the Debian/Ubuntu archive at all? Considering how often it is updated, it doesn't fit well for distros with a high barrier for updating packages in stable releases. – Gunnar Hjalmarsson Nov 29 '20 at 02:35
  • @deWalker: No worries about upvoting. :) I don't care much about the reputation thing. – Gunnar Hjalmarsson Nov 29 '20 at 02:37
  • 1
    @GunnarHjalmarsson for your last sentence, it is sufficient to just close and reopen the terminal to have .local/bin included in the path. ~/.profile is sourced each time you open a terminal. – vanadium Nov 29 '20 at 12:23
  • @vanadium: True. I had the graphical environment in mind, but it doesn't matter with youtube-dl which is a command line tool. – Gunnar Hjalmarsson Nov 29 '20 at 15:20
  • That applies to the graphical environment. What I mean is that you do not to log out log in to make that directory included in your path. It just suffices to relaunch the terminal to be able to launch it directly from the command line. So you could just mention that instead of suggesting that there is a need to log out then back in. – vanadium Nov 29 '20 at 15:49
  • @vanadium: I think I understood what you mean, and now I have also edited the answer accordingly. – Gunnar Hjalmarsson Nov 29 '20 at 16:03
  • 3
    @delWalker: Just as a general hint: If you see something in /usr/local, it never comes from Ubuntu. The whole point of that directory is that it is "owned" by the local sysadmin (for personal / home use that person is usually identical with the user), and will never be touched by the distribution. Hence the name "local". – Jörg W Mittag Nov 29 '20 at 16:17
  • @JörgWMittag: I knew that was how it worked in other distros I've used, but wasn't sure about Ubuntu... it's quite different with this snap tool - and I've never seen a system so conflicted over youtube-dl. So - thanks for the reassurance! – deWalker Nov 29 '20 at 19:01
  • 1
    @GunnarHjalmarsson: Got enough rep to upvote, so thanks again. – deWalker Nov 29 '20 at 19:02
  • @vanadium: wrt "relaunch the terminal": does Ubuntu not utilize the source command to have the shell re-read its configuration files? i.e. . ~/.bashrc? – Seamus Dec 01 '20 at 23:35
  • @Seamus: How does that command apply to this discussion? – Gunnar Hjalmarsson Dec 01 '20 at 23:56
  • @vanadium: Seems like you tricked me into an incorrect edit of the answer. I just changed it back. A relogin is needed - ~/.profile is only sourced for login shells. – Gunnar Hjalmarsson Dec 01 '20 at 23:59
  • @GunnarHjalmarsson: Perhaps I misunderstood vanadium's comment... thought he was suggesting that to re-read the ~/.bashrc file... apologies. But, will hash -r not avoid the necessity for logout/login ? – Seamus Dec 02 '20 at 00:13
  • 1
    @Seamus: The code for adding ~/.local/bin to PATH is in ~/.profile, so sourcing ~/.profile may be an option. But even if there is more than one way to do it, I think that relogin is a reasonable advice in the answer we are discussing here. – Gunnar Hjalmarsson Dec 02 '20 at 00:37
  • My apologies if I got this wrong, but stating that I "tricked" you is not so nice. Logout/login of course is a safer advice. – vanadium Dec 02 '20 at 11:19
  • @vanadium: Sorry for that word choice. I tested it only when Seamus entered the thread, and found that we both were mistaken. – Gunnar Hjalmarsson Dec 02 '20 at 17:53
  • @GunnarHjalmarsson You are welcome. I learned. – vanadium Dec 03 '20 at 10:29
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
  • 391