-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
  • 391
  • 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 05: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 05:38
  • @guiverc: My OS & release are Ubuntu 20.04 LTS - I thought that was clear from the question, but if I overlooked something, pls advise. And pls also note, I also asked the question you referenced - did you miss the links in this question? – deWalker Nov 29 '20 at 05:44
  • Sorry, details in headings are not always visible once the question is open depending on the device & browser being used to read the site. Thus all relevant details in headings should also exist in the question; where no release is mentioned on your page. – guiverc Nov 29 '20 at 05:47
  • @guiverc: As I indicated in this referenced question, I installed youtube-dl from the apt repo, and got a version from March of this year. And being installed from apt, it must be upgraded via apt. – deWalker Nov 29 '20 at 05:53
  • I don't program in python either, but using pip3 install youtub-dl I don't consider difficult, which you mentioned but also highlighted an issue... I'll see if I can find a recent 20.04.2 QA-test install & have a play for you. – guiverc Nov 29 '20 at 06:06
  • 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 06:15
  • I can write up what I did as an answer, it's what I'd do, in fact just did on a fresh (except for some df & like commands checking out the Quality Assurance install of the un-released Lubuntu 20.04.2 system; in reality it's just a 20.04 system. and I can't see Lubuntu making any difference; it was used as available), but I don't see that as anything beyond what has already been covered in your prior question.--upgrade doesn't make sense on a first install in your question so I didn't use it; my use of ln could be done other ways; but I find that way quick so used it.. – guiverc Nov 29 '20 at 06:27
  • @guiverc: I have added an extensive edit in an effort to address all of your comments and questions. If I indicated that the pip3 install did not get the 2020.11.26 ver of youtube-dl then I have mis-communicated. I think I said it worked in this question, and I accepted the answer I got on the previous question. Yes... it works, but as explained in my Edit, I don't want to use that solution. I think between Ubuntu & yt-dl, something is broken. It seems that installing from source may be a solution, but I don't know - thus, the question. – deWalker Nov 29 '20 at 07:20
  • pip3 install youtub-dl will install the source (a python3 script). You can then use whereis to locate where it was placed (I may have used whereis before I use the ln in prior comment), then a file can be used to confirm it's python3. eg. a file ..../youtube-dl reports "Python script, ASCII text executable" (ie. that is the source code; python3 is both source code & executable). I dropped (....) the path as this is the apt installer version on this box (2020.11.21.1) so I wouldn't expect it to be the same path as pip3 installed version I tested on focal 20.04.2 box – guiverc Nov 29 '20 at 07:28
  • I just see my youtube-dl is now an old version.... 2020.11.29 has come out... new versions of youtube-dl come out very regularly ... the focal version I tested (prior comment) worked though on the music video *I download & subsequently listened to. – guiverc Nov 29 '20 at 07:35
  • FYI: Whilst some languages are compiled into executable code (eg. C), most scripting languages (like python) are just interpreted by interpreters, and thus the source code and executable are one & the same thing. – guiverc Nov 29 '20 at 07:44
  • You don't need to use sudo when you install with pip (and you really shouldn't because it's not necessary). You simply need to add the --user flag to your pip command to install locally. After you install locally with pip for the first time, you will need to log out and log back in but this will not be necessary in the future. I have provided a simple answer below. – mchid Nov 29 '20 at 08:29
  • @guiverc You don't need to ln that local directory to /usr/local/bin so it can be found. You just need to log out and log back in after the first time you install something to $HOME/.local/bin as this directory is conditionally added to your path (if it exists) by ~/.profile. – mchid Nov 29 '20 at 09:01
  • If you used the ln command, just run the following command rm $HOME/.local/bin/youtube-dl and then follow my instructions below. – mchid Nov 29 '20 at 09:04
  • 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
  • Also, the reason they want it installed in /usr/local/bin is so that the downloaded version will override the version from apt. Also, if the apt version is updated, it won't overwrite your downloaded version. Typically, applications installed from source or manually downloaded will install in /usr/local/bin to allow apt version to stay installed which you may need for dependency reasons (so that other packages don't break due to dependencies) although, that shouldn't be an issue here. – mchid Nov 29 '20 at 15:32

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
  • 43,546
  • 8
  • 97
  • 150
  • 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 09:25
  • This doesn't answer the OP's question. – Seamus Nov 29 '20 at 09: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 00: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 01 '20 at 22:33
  • I didn't see your extensive edits until after I posted my previous comment. It's a much better answer now AFAIC, but I question the statement that ... install python-is-python3 is going to fix the No such file or directory error. It will address the /usr/bin/env: python: No such file or directory error. On my system I used hash -r to resolve this (see my answer). After struggling with the same issues as the OP, I think this is the way to go. – Seamus Dec 02 '20 at 02:20
  • @Seamus Yes, I was referring to the /usr/bin/env: ‘python’: No such file or directory since it appeared the /usr/local/bin error was resolved when they installed the downloaded version. Anyhow, fixed it by adding a command at the end to source the ~/.bashrc file just in case. – mchid Dec 02 '20 at 15:37
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
  • 636