How to fix "apt-get install -f apt-transport-https" error: 404 Not Found?

79,031

Solution 1

I appear to have fixed the issue by symlinking the https dir in /usr/lib/apt/methods to the http dir.

root@validator-dev-group-c2v4:~# cd /usr/lib/apt/methods
root@validator-dev-group-c2v4:/usr/lib/apt/methods# ln -s http https

Since I don't actually have any https:// sources configured it seems harmless and then when apt-get install apt-transport-https runs it actually overwrites the symlink with the correct files.

Solution 2

The general solution is to update apt's indexes so it knows which versions are available:

apt-get update

Then installing apt-transport-https will find the appropriate versions on the repositories.

You should do this every time you want to install a new package, unless you've done it recently (within the last day typically).

If you can't run apt-get update because it needs apt-transport-https, you can fix things by (temporarily) switching your https:// URLs to http:// in /etc/apt/sources.list (and perhaps files in /etc/apt/sources.list.d). Using HTTP to download packages doesn't reduce your security, it only reduces your confidentiality (systems between your computer and the repositories can see what packages you're retrieving).

If that doesn't work, you can try picking a specific mirror, which should avoid any redirections to HTTPS URLs; look at the list, pick a mirror close to you and use that instead of httpredir.debian.org in your sources.

In your specific case it may well be simpler to manually download the required packages (and ship them alongside your setup scripts so that they continue working): apt-transport-https, libapt-pkg4.12 and whatever else is necessary. (You may end up needing to upgrade apt at the same time.)

Solution 3

There are a bunch of text files containing the URL for downloading apt packages within the folder /etc/apt/

Example name for those text files can be: /etc/apt/sources.list.d/mssql-release.list if you try to install packages from a Microsoft server.

And the content of /etc/apt/sources.list.d/mssql-release.list could be :

deb [arch=amd64] https://packages.microsoft.com/debian/8/prod jessie main

Sometimes the content from *.list files is downloaded via HTTPS instead of HTTP but if you have not installed the package apt-transport-https, you wouldn't be able to update your apt-get package manager. It will keep warning you about not being able to use the HTTPS sources.

What you can do then is to locate the offending *.list file(s) with HTTPS links and rename it: sudo mv /etc/apt/sources.list.d/mssql-release.list /etc/apt/sources.list.d/mssql-release.list1 sudo apt-get update sudo apt-get install -y apt-transport-https sudo mv /etc/apt/sources.list.d/mssql-release.list1 /etc/apt/sources.list.d/mssql-release.list sudo apt-get update Then you should be able to proceed with whatever apt-get operations you wish to perform.

Reference for coming up with this answer https://community.c9.io/t/installing-apt-transport-https-issue/10994/10

Share:
79,031

Related videos on Youtube

Richard Corfield
Author by

Richard Corfield

Updated on September 18, 2022

Comments

  • Richard Corfield
    Richard Corfield over 1 year

    We have a pair of load balanced managed VMs which install apt-transport-https as part of a startup script.

    However recently the servers went into an error state because on startup they could no longer download the version of the package required (1.0.9.8.3) because it is no longer present on the mirror: http://httpredir.debian.org/debian/pool/main/a/apt

    root@validator-dev-group-c2v4:/etc# apt-get install -f apt-transport-https
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      apt-transport-https
    0 upgraded, 1 newly installed, 0 to remove and 27 not upgraded.
    Need to get 138 kB of archives.
    After this operation, 195 kB of additional disk space will be used.
    Err http://httpredir.debian.org/debian/ jessie/main apt-transport-https amd64 1.0.9.8.3
      404  Not Found
    E: Failed to fetch http://httpredir.debian.org/debian/pool/main/a/apt/apt-transport-https_1.0.9.8.3_amd64.deb  404  Not Found
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
    

    Trying the suggestion of --fix-missing does not help.

    root@validator-dev-group-c2v4:/etc# apt-get install --fix-missing apt-transport-https
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      apt-transport-https
    0 upgraded, 1 newly installed, 0 to remove and 27 not upgraded.
    Need to get 138 kB of archives.
    After this operation, 195 kB of additional disk space will be used.
    Err http://httpredir.debian.org/debian/ jessie/main apt-transport-https amd64 1.0.9.8.3
      404  Not Found
    E: Failed to fetch http://httpredir.debian.org/debian/pool/main/a/apt/apt-transport-https_1.0.9.8.3_amd64.deb  404  Not Found
    E: Internal Error, ordering was unable to handle the media swap
    

    Next I manually downloaded the higher version of apt-transport-https (1.0.9.8.4) bug I was unable to install it directly because of a dependency on libapt-pkg4.12.

    root@validator-dev-group-c2v4:/home/<user># sudo dpkg -i ./apt-transport-https_1.0.9.8.4_amd64.deb 
    Selecting previously unselected package apt-transport-https.
    (Reading database ... 26719 files and directories currently installed.)
    Preparing to unpack .../apt-transport-https_1.0.9.8.4_amd64.deb ...
    Unpacking apt-transport-https (1.0.9.8.4) ...
    dpkg: dependency problems prevent configuration of apt-transport-https:
     apt-transport-https depends on libapt-pkg4.12 (>= 1.0.9.8.4); however:
      Version of libapt-pkg4.12:amd64 on system is 1.0.9.8.3.
    

    Can anyone help me resolve this problem? Is it as simple as upgrading libapt-pkg4.12? If so, how do I go about that?

    EDIT: Also I am unable to run apt-get update ... because I haven't got apt-transport-https installed. Which I think they call Catch-22!

    root@validator-dev-group-c2v4:/home/<user># apt-get update
    E: The method driver /usr/lib/apt/methods/https could not be found.
    N: Is the package apt-transport-https installed?
    

    This is what my /etc/apt/sources.list looks like:

    deb http://httpredir.debian.org/debian/ jessie main
    deb-src http://httpredir.debian.org/debian/ jessie main
    deb http://security.debian.org/ jessie/updates main
    deb-src http://security.debian.org/ jessie/updates main
    deb http://httpredir.debian.org/debian/ jessie-updates main
    deb-src http://httpredir.debian.org/debian/ jessie-updates main
    

    Thank you in advance

    • drjors
      drjors over 7 years
      Have you run apt-get update recently? You should have an updated list of what's available from the repositories, before you try to install any given package. 404 is likely happening because you're trying to install a version of the package that is no longer on the repository servers.
    • Richard Corfield
      Richard Corfield over 7 years
      Good question. I forgot to mention this, so I'll edit the question. I can't run apt-get update because I haven't got apt-transport-https installed!!! A nice Catch-22
    • ctrl-alt-delor
      ctrl-alt-delor over 7 years
      Better to have your own repo, so you don't depend on an external one.
    • Stephen Kitt
      Stephen Kitt over 7 years
      Do you have anything in files in /etc/apt/sources.list.d?
    • Richard Corfield
      Richard Corfield over 7 years
      Only lines already present in sources.list: deb httpredir.debian.org/debian jessie-backports main deb-src httpredir.debian.org/debian jessie-backports main None of the entries in either location contain 'https://' URLs though?
    • Stephen Kitt
      Stephen Kitt over 7 years
      Indeed, perhaps the redirector is sending you to an HTTPS mirror...
    • Bethwel Too
      Bethwel Too almost 7 years
      Renaming the http to https in /usr/lib/apt/methods/ solved my problem.
    • William Isted
      William Isted about 5 years
      Thank you @Bethwel Too, this has solved an issue on the now defunct C.H.I.P.
  • Richard Corfield
    Richard Corfield over 7 years
    I can't run apt-get update because I haven't got apt-transport-https installed!
  • Stephen Kitt
    Stephen Kitt over 7 years
    Ah yes, see my update.
  • Stephen Kitt
    Stephen Kitt over 7 years
    OK, you could try another mirror, or just manually download everything.
  • Jeff Schaller
    Jeff Schaller about 5 years
    Your last sentence seems to have been cut off. Also, the OP made no mention of a proxy...?
  • antisa
    antisa over 2 years
    Awesome trick, worked like a charm!
  • Ajax
    Ajax over 2 years
    This is what allowed me to unbreak our entire companies build process when a docker image pointing to an old mono repo stopped working. RUN find /etc/apt/sources.list.d -type f -exec bash -c 'mv $1 ${1}.bak' -- {} \; && \ apt-get update && apt-get install -y apt-transport-https && \ find /etc/apt/sources.list.d -type f -exec bash -c 'mv $1 ${1//.bak}' -- {} \;