-1

I have recently had some issues installing youtube-dl on Ubuntu 20.04. THIS IS NOT THE SAME QUESTION. Those issues have been resolved, but I am not:

And it seems the apt repository is not maintaining a current, operational version of youtube-dl, so my preferred approach won't work.

It seems that installing youtube-dl from source would be a good solution. I've not done this on Ubuntu, and have very limited experience on any plaform. I've found what appears to be a decent guide, but nothing specific for youtube-dl on Ubuntu. Is there anything else I should know before proceeding?


Other Notes (Edit):

Just to confirm that sudo apt-get install youtube-dl has issues:

Preparing to unpack .../12-youtube-dl_2020.03.24-1_all.deb ...
Unpacking youtube-dl (2020.03.24-1) ...
Setting up youtube-dl (2020.03.24-1) ...

After the apt installation of youtube-dl completes successfully:

$ which youtube-dl
/usr/bin/youtube-dl 
$ youtube-dl --version
bash: /usr/local/bin/youtube-dl: No such file or directory
$ /usr/bin/youtube-dl --version
2020.03.24

Which suggests to a newbie such as I that something is amiss. Note that there is confusion wrt where youtube-dl is installed: /usr/bin vs /usr/local/bin. And it clearly installs an old (March, 2020) version.

Using the install procedure from the youtube-dl github page yields this:

$ sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl  
$ sudo chmod a+rx /usr/local/bin/youtube-dl  
$ youtube-dl --version
/usr/bin/env: ‘python’: No such file or directory

For reasons unclear to me, the youtube-dl maintainers want the installation in /usr/local/bin. No idea why python is expected in /usr/bin/env.

All the above is to address various comments made since this Q was submitted.

And yes, if I uninstall/remove/reverse the apt install, and delete the curl'd d/l to /usr/local/bin, I can successfully install and run youtube-dl using sudo pip3. But some caution that sudo pip3 should NOT be done - rather it should be virtualenv (or something like that) instead. That is why I have posted this question: I don't want to use something I don't don't use & don't understand because I can't maintain it. I don't think that's unreasonable or makes me recalcitrant. I just want to know how to install youtube-dl from source - if that is a reasonable thing to do given all of the above.

deWalker
  • 401

2 Answers2

2

Before you begin, run the following commands to fix your #!/usr/bin/env python "No such file or directory" error:

sudo apt update
sudo apt install python-is-python3

Now, your problem is most likely solved. However, you can check out the following instructions if you want to install from source.


Make sure all the old versions are uninstalled:

sudo apt purge youtube-dl
sudo pip3 uninstall youtube-dl
pip3 uninstall youtube-dl
sudo rm /usr/local/bin/youtube-dl
rm $HOME/.local/bin/youtube-dl

Now, install from source:

cd
sudo apt update
sudo apt install git
sudo apt build-dep youtube-dl
git clone https://github.com/ytdl-org/youtube-dl.git
cd youtube-dl
make
sudo make install
. ~/.bashrc  
mchid
  • 44,904
  • 8
  • 102
  • 162
0

I suspect that the reason you are getting the error is due strictly to the fact that your shell saves the location of executables (and other things) to its cache. In other words:

After you installed youtube-dl using apt, you then entered a command to check the version (youtube-dl --version). At that point, /usr/bin/youtube-dl was stored in the cache. This is efficient because it avoids searching your PATH each time you enter that command. But if you then re-install youtube-dl using the manual installation procedure, the new location is /usr/local/bin/youtube-dl. But the cache is not updated by the new "installation", nor is it updated when you run apt remove on the youtube-dl package you installed. Consequently, the shell tries to run the wrong executable - or even one that's no longer there.

Proposed Answer:

The solution to the No such file or directory error is this:

$ type youtube-dl

this will likely show the following:

youtube-dl is hashed (/usr/bin/youtube-dl)

if this is the case, your "fix" is one of the following:

$ hash -r

which will delete the entire cache

--OR--

$ hash -d youtube-dl

which will delete only the entry for youtube-dl

hash is a bash built-in; search for hash in man bash for more details. For zsh users, the analog to hash is rehash.

Also, the youtube-dl manual installation was done in /usr/local/bin iaw long-standing procedure explained in this article on Linux directory structure. This is as it should be - no fault to Ubuntu or to the yt-dl maintainers.

Installing From source:

This answer does not address your question re "installing from source". Another answer proposes an approach for this, but I doubt that installing from source would have avoided the No such file or directory error in any case - except possibly by accident - for example you started a new session.

Seamus
  • 698