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
$ youtube-dl --version
bash: /usr/local/bin/youtube-dl: No such file or directory
$ /usr/bin/youtube-dl --version

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.

  • You haven't mentioned your OS & release, but I have no issues with my apt installed 2020.11.21.1 version (you're likely to have a different version if your release differs). Why not just pip3 install it as Gunnar Hjalmarsson suggested. It's worked for me in the past. – guiverc Nov 29 '20 at 5:35
  • 2
  • The Ubuntu repositories are maintained, but as it's a 'universe' package, it's maintained by the Community, and it's not recorded that a package needs to be refreshed until a user who is having an issue, then files a bug reporting a re-package is required. Users reporting issues starts the process of maintenance. As I stated before, I've done that a couple of times with youtube-dl and the upgraded package usually is available 28-52 hours later (as it's community packaged, it's a volunteer in their own time packaging it, and delays can occur, but the process is started with bug filing) – guiverc Nov 29 '20 at 5:38
  • 2
    A clean (other than the few commands I use to verify the QA-test install) 20.04.2 install was booted, sudo apt install python3-pip, followed by pip3 install youtube-dl, next sudo ln -s /home/guiverc/.local/bin/youtube-dl /usr/local/bin/youtube-dl so it can be found (it's quick) then a youtube --version reports the version as 2020.11.26 which is not the version you got in your prior question. It works too downloading a youtube video. – guiverc Nov 29 '20 at 6:15
  • 1
    @mchid I realize that; but the ln command was far quicker than logout/login (esp. given it took me ~4 goes to remember which password was used in that QA-test)... – guiverc Nov 29 '20 at 12:42

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:

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
sudo make install
. ~/.bashrc  
  • If you used the ln command earlier, just run the following command rm $HOME/.local/bin/youtube-dl and you may need to run pip uninstall youtube-dl then follow my instructions in this answer. – mchid Nov 29 '20 at 9:25
  • This doesn't answer the OP's question. – Seamus Nov 29 '20 at 9:36
  • @Seamus In any case, I added the instructions for installing from source. – mchid Nov 29 '20 at 11:55
  • @Seamus Although, it the same as the pre-compiled downloaded version anyhow (if you run make and sudo make install without changing any options). – mchid Nov 30 '20 at 0:45
  • If that's the case, I wonder why doing the manual installation results in an error when you try to run it? Specifically: bash: /usr/bin/youtube-dl: No such file or directory after installing it in /usr/local/bin?? Why is this? usr/local/bin is in my PATH, which knows it's in usr/local/bin. Not trying to be an a$$hole, but what I see on my system doesn't agree with what you say. If I've made another error, please let me know. – Seamus Dec 1 '20 at 22:33

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.