How to switch APT mirror from the commandline?











up vote
3
down vote

favorite
1












Let's assume that we are using Ubuntu 18.04 LTS (Bionic Beaver).



I know GUI ways to switch currently used APT mirror.



User should open Software & Updates (software-properties-gtk or software-properties-kde) and navigate to Ubuntu Software (Kubuntu Software) tab and then select mirror in Download from list:



picking mirror



But how to switch APT mirror from the commandline?



Notes/updates:




  1. I need a solution without direct editing of /etc/apt/sources.list to prevent typos and automate correct mirror selection.

  2. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).










share|improve this question




















  • 1




    Why don't you want to edit sources.list? That's kind of the way to do it from the command line. All the GUI tools do is manipulate that file anyway.
    – terdon
    Nov 16 at 12:48










  • So you're OK if the solution does edit the file just as long as the solution isn't "go edit the file yourself"? SO, for instance, a sed command would work for you? If so, please show us an example of the alternate mirror's URL.
    – terdon
    Nov 16 at 12:56










  • My main idea is the following. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).
    – N0rbert
    Nov 16 at 12:58















up vote
3
down vote

favorite
1












Let's assume that we are using Ubuntu 18.04 LTS (Bionic Beaver).



I know GUI ways to switch currently used APT mirror.



User should open Software & Updates (software-properties-gtk or software-properties-kde) and navigate to Ubuntu Software (Kubuntu Software) tab and then select mirror in Download from list:



picking mirror



But how to switch APT mirror from the commandline?



Notes/updates:




  1. I need a solution without direct editing of /etc/apt/sources.list to prevent typos and automate correct mirror selection.

  2. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).










share|improve this question




















  • 1




    Why don't you want to edit sources.list? That's kind of the way to do it from the command line. All the GUI tools do is manipulate that file anyway.
    – terdon
    Nov 16 at 12:48










  • So you're OK if the solution does edit the file just as long as the solution isn't "go edit the file yourself"? SO, for instance, a sed command would work for you? If so, please show us an example of the alternate mirror's URL.
    – terdon
    Nov 16 at 12:56










  • My main idea is the following. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).
    – N0rbert
    Nov 16 at 12:58













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





Let's assume that we are using Ubuntu 18.04 LTS (Bionic Beaver).



I know GUI ways to switch currently used APT mirror.



User should open Software & Updates (software-properties-gtk or software-properties-kde) and navigate to Ubuntu Software (Kubuntu Software) tab and then select mirror in Download from list:



picking mirror



But how to switch APT mirror from the commandline?



Notes/updates:




  1. I need a solution without direct editing of /etc/apt/sources.list to prevent typos and automate correct mirror selection.

  2. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).










share|improve this question















Let's assume that we are using Ubuntu 18.04 LTS (Bionic Beaver).



I know GUI ways to switch currently used APT mirror.



User should open Software & Updates (software-properties-gtk or software-properties-kde) and navigate to Ubuntu Software (Kubuntu Software) tab and then select mirror in Download from list:



picking mirror



But how to switch APT mirror from the commandline?



Notes/updates:




  1. I need a solution without direct editing of /etc/apt/sources.list to prevent typos and automate correct mirror selection.

  2. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).







command-line apt package-management updates update-manager






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 1:27









muru

134k19282482




134k19282482










asked Nov 16 at 12:06









N0rbert

19.3k54290




19.3k54290








  • 1




    Why don't you want to edit sources.list? That's kind of the way to do it from the command line. All the GUI tools do is manipulate that file anyway.
    – terdon
    Nov 16 at 12:48










  • So you're OK if the solution does edit the file just as long as the solution isn't "go edit the file yourself"? SO, for instance, a sed command would work for you? If so, please show us an example of the alternate mirror's URL.
    – terdon
    Nov 16 at 12:56










  • My main idea is the following. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).
    – N0rbert
    Nov 16 at 12:58














  • 1




    Why don't you want to edit sources.list? That's kind of the way to do it from the command line. All the GUI tools do is manipulate that file anyway.
    – terdon
    Nov 16 at 12:48










  • So you're OK if the solution does edit the file just as long as the solution isn't "go edit the file yourself"? SO, for instance, a sed command would work for you? If so, please show us an example of the alternate mirror's URL.
    – terdon
    Nov 16 at 12:56










  • My main idea is the following. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).
    – N0rbert
    Nov 16 at 12:58








1




1




Why don't you want to edit sources.list? That's kind of the way to do it from the command line. All the GUI tools do is manipulate that file anyway.
– terdon
Nov 16 at 12:48




Why don't you want to edit sources.list? That's kind of the way to do it from the command line. All the GUI tools do is manipulate that file anyway.
– terdon
Nov 16 at 12:48












So you're OK if the solution does edit the file just as long as the solution isn't "go edit the file yourself"? SO, for instance, a sed command would work for you? If so, please show us an example of the alternate mirror's URL.
– terdon
Nov 16 at 12:56




So you're OK if the solution does edit the file just as long as the solution isn't "go edit the file yourself"? SO, for instance, a sed command would work for you? If so, please show us an example of the alternate mirror's URL.
– terdon
Nov 16 at 12:56












My main idea is the following. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).
– N0rbert
Nov 16 at 12:58




My main idea is the following. I need to switch mirror with one simple command as equivalent of picking one from Download from list in software-properties-gtk (also it is interesting where mirror addresses are saved in the system).
– N0rbert
Nov 16 at 12:58










2 Answers
2






active

oldest

votes

















up vote
4
down vote













Some solution (tested on my Ubuntu 18.04.1 LTS): https://github.com/jblakeman/apt-select.git



Install:



pip install apt-select


or:



pip3 install apt-select


Adding script to PATH to run it from everywhere (make it permanent):



export PATH=$PATH:~/.local/bin/apt-select


Examples usage:



Get the top mirror from the United States to generate a new sources.list::



apt-select --country US


Choose from the top 3 mirrors, including those last updated a week ago::



apt-select -c -t 3 -m one-week-behind


Select from 5 US mirrors with the lowest latency to your machine:



$ apt-select --country US -t 5 --choose





share|improve this answer























  • Thank you. Fixed last example.
    – S_Flash
    Nov 16 at 14:08


















up vote
1
down vote













List of mirror servers are retrieved by Python library (the get_server_list procedure is defined in /usr/lib/python3/dist-packages/aptsources/distro.py and called from /usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py).



The solution is to use tool named apt-mirror-updater. It is installable from pip/pip3:



sudo pip3 install apt-mirror-updater


Functionality:




Usage: apt-mirror-updater [OPTIONS]



The apt-mirror-updater program automates robust apt-get mirror
selection for Debian and Ubuntu by enabling discovery of available
mirrors, ranking of available mirrors, automatic switching between
mirrors and robust package list updating.



Supported options:



-r, --remote-host=SSH_ALIAS



Operate on a remote system instead of the local system. The SSH_ALIAS
argument gives the SSH alias of the remote host. It is assumed that the
remote account has root privileges or password-less sudo access.


-f, --find-current-mirror



Determine the main mirror that is currently configured in
/etc/apt/sources.list and report its URL on standard output.


-b, --find-best-mirror



Discover available mirrors, rank them, select the best one and report its
URL on standard output.


-l, --list-mirrors



List available (ranked) mirrors on the terminal in a human readable format.


-c, --change-mirror=MIRROR_URL



Update /etc/apt/sources.list to use the given MIRROR_URL.


-a, --auto-change-mirror



Discover available mirrors, rank the mirrors by connection speed and update
status and update /etc/apt/sources.list to use the best available mirror.


-u, --update, --update-package-lists



Update the package lists using `apt-get update', retrying on failure and
automatically switch to a different mirror when it looks like the current
mirror is being updated.


-x, --exclude=PATTERN



Add a pattern to the mirror selection blacklist. PATTERN is expected to be
a shell pattern (containing wild cards like `?' and `*') that is matched
against the full URL of each mirror.


-m, --max=COUNT



Don't query more than COUNT mirrors for their connection status
(defaults to 50). If you give the number 0 no limit will be applied.

Because Ubuntu mirror discovery can report more than 300 mirrors it's
useful to limit the number of mirrors that are queried, otherwise the
ranking of mirrors will take a long time (because over 300 connections
need to be established).


-v, --verbose



Increase logging verbosity (can be repeated).


-q, --quiet



Decrease logging verbosity (can be repeated).


-h, --help



Show this message and exit.



So it allows to find best mirror and apply it to /etc/apt/sources.list:



sudo apt-mirror-updater --auto-change-mirror


Also it allows to select mirror by URL and apply it to /etc/apt/sources.list:



$ apt-mirror-updater --list-mirrors
-----------------------------------------------------------------------------------------------------------------------
| Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
-----------------------------------------------------------------------------------------------------------------------
| 1 | http://mirror.timeweb.ru/ubuntu | Yes | No | Up to date | 6.49 KB/s |
| 2 | http://no.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 6.38 KB/s |
| 3 | http://ftp.aso.ee/ubuntu | Yes | No | Up to date | 5.62 KB/s |
| 4 | http://mirror.plusserver.com/ubuntu/ubuntu | Yes | No | Up to date | 4.77 KB/s |
| 5 | http://nl.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 4.68 KB/s |
...


and then select mirror by hand:



sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1093451%2fhow-to-switch-apt-mirror-from-the-commandline%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    Some solution (tested on my Ubuntu 18.04.1 LTS): https://github.com/jblakeman/apt-select.git



    Install:



    pip install apt-select


    or:



    pip3 install apt-select


    Adding script to PATH to run it from everywhere (make it permanent):



    export PATH=$PATH:~/.local/bin/apt-select


    Examples usage:



    Get the top mirror from the United States to generate a new sources.list::



    apt-select --country US


    Choose from the top 3 mirrors, including those last updated a week ago::



    apt-select -c -t 3 -m one-week-behind


    Select from 5 US mirrors with the lowest latency to your machine:



    $ apt-select --country US -t 5 --choose





    share|improve this answer























    • Thank you. Fixed last example.
      – S_Flash
      Nov 16 at 14:08















    up vote
    4
    down vote













    Some solution (tested on my Ubuntu 18.04.1 LTS): https://github.com/jblakeman/apt-select.git



    Install:



    pip install apt-select


    or:



    pip3 install apt-select


    Adding script to PATH to run it from everywhere (make it permanent):



    export PATH=$PATH:~/.local/bin/apt-select


    Examples usage:



    Get the top mirror from the United States to generate a new sources.list::



    apt-select --country US


    Choose from the top 3 mirrors, including those last updated a week ago::



    apt-select -c -t 3 -m one-week-behind


    Select from 5 US mirrors with the lowest latency to your machine:



    $ apt-select --country US -t 5 --choose





    share|improve this answer























    • Thank you. Fixed last example.
      – S_Flash
      Nov 16 at 14:08













    up vote
    4
    down vote










    up vote
    4
    down vote









    Some solution (tested on my Ubuntu 18.04.1 LTS): https://github.com/jblakeman/apt-select.git



    Install:



    pip install apt-select


    or:



    pip3 install apt-select


    Adding script to PATH to run it from everywhere (make it permanent):



    export PATH=$PATH:~/.local/bin/apt-select


    Examples usage:



    Get the top mirror from the United States to generate a new sources.list::



    apt-select --country US


    Choose from the top 3 mirrors, including those last updated a week ago::



    apt-select -c -t 3 -m one-week-behind


    Select from 5 US mirrors with the lowest latency to your machine:



    $ apt-select --country US -t 5 --choose





    share|improve this answer














    Some solution (tested on my Ubuntu 18.04.1 LTS): https://github.com/jblakeman/apt-select.git



    Install:



    pip install apt-select


    or:



    pip3 install apt-select


    Adding script to PATH to run it from everywhere (make it permanent):



    export PATH=$PATH:~/.local/bin/apt-select


    Examples usage:



    Get the top mirror from the United States to generate a new sources.list::



    apt-select --country US


    Choose from the top 3 mirrors, including those last updated a week ago::



    apt-select -c -t 3 -m one-week-behind


    Select from 5 US mirrors with the lowest latency to your machine:



    $ apt-select --country US -t 5 --choose






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 16 at 14:07

























    answered Nov 16 at 13:33









    S_Flash

    888117




    888117












    • Thank you. Fixed last example.
      – S_Flash
      Nov 16 at 14:08


















    • Thank you. Fixed last example.
      – S_Flash
      Nov 16 at 14:08
















    Thank you. Fixed last example.
    – S_Flash
    Nov 16 at 14:08




    Thank you. Fixed last example.
    – S_Flash
    Nov 16 at 14:08












    up vote
    1
    down vote













    List of mirror servers are retrieved by Python library (the get_server_list procedure is defined in /usr/lib/python3/dist-packages/aptsources/distro.py and called from /usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py).



    The solution is to use tool named apt-mirror-updater. It is installable from pip/pip3:



    sudo pip3 install apt-mirror-updater


    Functionality:




    Usage: apt-mirror-updater [OPTIONS]



    The apt-mirror-updater program automates robust apt-get mirror
    selection for Debian and Ubuntu by enabling discovery of available
    mirrors, ranking of available mirrors, automatic switching between
    mirrors and robust package list updating.



    Supported options:



    -r, --remote-host=SSH_ALIAS



    Operate on a remote system instead of the local system. The SSH_ALIAS
    argument gives the SSH alias of the remote host. It is assumed that the
    remote account has root privileges or password-less sudo access.


    -f, --find-current-mirror



    Determine the main mirror that is currently configured in
    /etc/apt/sources.list and report its URL on standard output.


    -b, --find-best-mirror



    Discover available mirrors, rank them, select the best one and report its
    URL on standard output.


    -l, --list-mirrors



    List available (ranked) mirrors on the terminal in a human readable format.


    -c, --change-mirror=MIRROR_URL



    Update /etc/apt/sources.list to use the given MIRROR_URL.


    -a, --auto-change-mirror



    Discover available mirrors, rank the mirrors by connection speed and update
    status and update /etc/apt/sources.list to use the best available mirror.


    -u, --update, --update-package-lists



    Update the package lists using `apt-get update', retrying on failure and
    automatically switch to a different mirror when it looks like the current
    mirror is being updated.


    -x, --exclude=PATTERN



    Add a pattern to the mirror selection blacklist. PATTERN is expected to be
    a shell pattern (containing wild cards like `?' and `*') that is matched
    against the full URL of each mirror.


    -m, --max=COUNT



    Don't query more than COUNT mirrors for their connection status
    (defaults to 50). If you give the number 0 no limit will be applied.

    Because Ubuntu mirror discovery can report more than 300 mirrors it's
    useful to limit the number of mirrors that are queried, otherwise the
    ranking of mirrors will take a long time (because over 300 connections
    need to be established).


    -v, --verbose



    Increase logging verbosity (can be repeated).


    -q, --quiet



    Decrease logging verbosity (can be repeated).


    -h, --help



    Show this message and exit.



    So it allows to find best mirror and apply it to /etc/apt/sources.list:



    sudo apt-mirror-updater --auto-change-mirror


    Also it allows to select mirror by URL and apply it to /etc/apt/sources.list:



    $ apt-mirror-updater --list-mirrors
    -----------------------------------------------------------------------------------------------------------------------
    | Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
    -----------------------------------------------------------------------------------------------------------------------
    | 1 | http://mirror.timeweb.ru/ubuntu | Yes | No | Up to date | 6.49 KB/s |
    | 2 | http://no.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 6.38 KB/s |
    | 3 | http://ftp.aso.ee/ubuntu | Yes | No | Up to date | 5.62 KB/s |
    | 4 | http://mirror.plusserver.com/ubuntu/ubuntu | Yes | No | Up to date | 4.77 KB/s |
    | 5 | http://nl.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 4.68 KB/s |
    ...


    and then select mirror by hand:



    sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"





    share|improve this answer

























      up vote
      1
      down vote













      List of mirror servers are retrieved by Python library (the get_server_list procedure is defined in /usr/lib/python3/dist-packages/aptsources/distro.py and called from /usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py).



      The solution is to use tool named apt-mirror-updater. It is installable from pip/pip3:



      sudo pip3 install apt-mirror-updater


      Functionality:




      Usage: apt-mirror-updater [OPTIONS]



      The apt-mirror-updater program automates robust apt-get mirror
      selection for Debian and Ubuntu by enabling discovery of available
      mirrors, ranking of available mirrors, automatic switching between
      mirrors and robust package list updating.



      Supported options:



      -r, --remote-host=SSH_ALIAS



      Operate on a remote system instead of the local system. The SSH_ALIAS
      argument gives the SSH alias of the remote host. It is assumed that the
      remote account has root privileges or password-less sudo access.


      -f, --find-current-mirror



      Determine the main mirror that is currently configured in
      /etc/apt/sources.list and report its URL on standard output.


      -b, --find-best-mirror



      Discover available mirrors, rank them, select the best one and report its
      URL on standard output.


      -l, --list-mirrors



      List available (ranked) mirrors on the terminal in a human readable format.


      -c, --change-mirror=MIRROR_URL



      Update /etc/apt/sources.list to use the given MIRROR_URL.


      -a, --auto-change-mirror



      Discover available mirrors, rank the mirrors by connection speed and update
      status and update /etc/apt/sources.list to use the best available mirror.


      -u, --update, --update-package-lists



      Update the package lists using `apt-get update', retrying on failure and
      automatically switch to a different mirror when it looks like the current
      mirror is being updated.


      -x, --exclude=PATTERN



      Add a pattern to the mirror selection blacklist. PATTERN is expected to be
      a shell pattern (containing wild cards like `?' and `*') that is matched
      against the full URL of each mirror.


      -m, --max=COUNT



      Don't query more than COUNT mirrors for their connection status
      (defaults to 50). If you give the number 0 no limit will be applied.

      Because Ubuntu mirror discovery can report more than 300 mirrors it's
      useful to limit the number of mirrors that are queried, otherwise the
      ranking of mirrors will take a long time (because over 300 connections
      need to be established).


      -v, --verbose



      Increase logging verbosity (can be repeated).


      -q, --quiet



      Decrease logging verbosity (can be repeated).


      -h, --help



      Show this message and exit.



      So it allows to find best mirror and apply it to /etc/apt/sources.list:



      sudo apt-mirror-updater --auto-change-mirror


      Also it allows to select mirror by URL and apply it to /etc/apt/sources.list:



      $ apt-mirror-updater --list-mirrors
      -----------------------------------------------------------------------------------------------------------------------
      | Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
      -----------------------------------------------------------------------------------------------------------------------
      | 1 | http://mirror.timeweb.ru/ubuntu | Yes | No | Up to date | 6.49 KB/s |
      | 2 | http://no.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 6.38 KB/s |
      | 3 | http://ftp.aso.ee/ubuntu | Yes | No | Up to date | 5.62 KB/s |
      | 4 | http://mirror.plusserver.com/ubuntu/ubuntu | Yes | No | Up to date | 4.77 KB/s |
      | 5 | http://nl.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 4.68 KB/s |
      ...


      and then select mirror by hand:



      sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        List of mirror servers are retrieved by Python library (the get_server_list procedure is defined in /usr/lib/python3/dist-packages/aptsources/distro.py and called from /usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py).



        The solution is to use tool named apt-mirror-updater. It is installable from pip/pip3:



        sudo pip3 install apt-mirror-updater


        Functionality:




        Usage: apt-mirror-updater [OPTIONS]



        The apt-mirror-updater program automates robust apt-get mirror
        selection for Debian and Ubuntu by enabling discovery of available
        mirrors, ranking of available mirrors, automatic switching between
        mirrors and robust package list updating.



        Supported options:



        -r, --remote-host=SSH_ALIAS



        Operate on a remote system instead of the local system. The SSH_ALIAS
        argument gives the SSH alias of the remote host. It is assumed that the
        remote account has root privileges or password-less sudo access.


        -f, --find-current-mirror



        Determine the main mirror that is currently configured in
        /etc/apt/sources.list and report its URL on standard output.


        -b, --find-best-mirror



        Discover available mirrors, rank them, select the best one and report its
        URL on standard output.


        -l, --list-mirrors



        List available (ranked) mirrors on the terminal in a human readable format.


        -c, --change-mirror=MIRROR_URL



        Update /etc/apt/sources.list to use the given MIRROR_URL.


        -a, --auto-change-mirror



        Discover available mirrors, rank the mirrors by connection speed and update
        status and update /etc/apt/sources.list to use the best available mirror.


        -u, --update, --update-package-lists



        Update the package lists using `apt-get update', retrying on failure and
        automatically switch to a different mirror when it looks like the current
        mirror is being updated.


        -x, --exclude=PATTERN



        Add a pattern to the mirror selection blacklist. PATTERN is expected to be
        a shell pattern (containing wild cards like `?' and `*') that is matched
        against the full URL of each mirror.


        -m, --max=COUNT



        Don't query more than COUNT mirrors for their connection status
        (defaults to 50). If you give the number 0 no limit will be applied.

        Because Ubuntu mirror discovery can report more than 300 mirrors it's
        useful to limit the number of mirrors that are queried, otherwise the
        ranking of mirrors will take a long time (because over 300 connections
        need to be established).


        -v, --verbose



        Increase logging verbosity (can be repeated).


        -q, --quiet



        Decrease logging verbosity (can be repeated).


        -h, --help



        Show this message and exit.



        So it allows to find best mirror and apply it to /etc/apt/sources.list:



        sudo apt-mirror-updater --auto-change-mirror


        Also it allows to select mirror by URL and apply it to /etc/apt/sources.list:



        $ apt-mirror-updater --list-mirrors
        -----------------------------------------------------------------------------------------------------------------------
        | Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
        -----------------------------------------------------------------------------------------------------------------------
        | 1 | http://mirror.timeweb.ru/ubuntu | Yes | No | Up to date | 6.49 KB/s |
        | 2 | http://no.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 6.38 KB/s |
        | 3 | http://ftp.aso.ee/ubuntu | Yes | No | Up to date | 5.62 KB/s |
        | 4 | http://mirror.plusserver.com/ubuntu/ubuntu | Yes | No | Up to date | 4.77 KB/s |
        | 5 | http://nl.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 4.68 KB/s |
        ...


        and then select mirror by hand:



        sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"





        share|improve this answer












        List of mirror servers are retrieved by Python library (the get_server_list procedure is defined in /usr/lib/python3/dist-packages/aptsources/distro.py and called from /usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py).



        The solution is to use tool named apt-mirror-updater. It is installable from pip/pip3:



        sudo pip3 install apt-mirror-updater


        Functionality:




        Usage: apt-mirror-updater [OPTIONS]



        The apt-mirror-updater program automates robust apt-get mirror
        selection for Debian and Ubuntu by enabling discovery of available
        mirrors, ranking of available mirrors, automatic switching between
        mirrors and robust package list updating.



        Supported options:



        -r, --remote-host=SSH_ALIAS



        Operate on a remote system instead of the local system. The SSH_ALIAS
        argument gives the SSH alias of the remote host. It is assumed that the
        remote account has root privileges or password-less sudo access.


        -f, --find-current-mirror



        Determine the main mirror that is currently configured in
        /etc/apt/sources.list and report its URL on standard output.


        -b, --find-best-mirror



        Discover available mirrors, rank them, select the best one and report its
        URL on standard output.


        -l, --list-mirrors



        List available (ranked) mirrors on the terminal in a human readable format.


        -c, --change-mirror=MIRROR_URL



        Update /etc/apt/sources.list to use the given MIRROR_URL.


        -a, --auto-change-mirror



        Discover available mirrors, rank the mirrors by connection speed and update
        status and update /etc/apt/sources.list to use the best available mirror.


        -u, --update, --update-package-lists



        Update the package lists using `apt-get update', retrying on failure and
        automatically switch to a different mirror when it looks like the current
        mirror is being updated.


        -x, --exclude=PATTERN



        Add a pattern to the mirror selection blacklist. PATTERN is expected to be
        a shell pattern (containing wild cards like `?' and `*') that is matched
        against the full URL of each mirror.


        -m, --max=COUNT



        Don't query more than COUNT mirrors for their connection status
        (defaults to 50). If you give the number 0 no limit will be applied.

        Because Ubuntu mirror discovery can report more than 300 mirrors it's
        useful to limit the number of mirrors that are queried, otherwise the
        ranking of mirrors will take a long time (because over 300 connections
        need to be established).


        -v, --verbose



        Increase logging verbosity (can be repeated).


        -q, --quiet



        Decrease logging verbosity (can be repeated).


        -h, --help



        Show this message and exit.



        So it allows to find best mirror and apply it to /etc/apt/sources.list:



        sudo apt-mirror-updater --auto-change-mirror


        Also it allows to select mirror by URL and apply it to /etc/apt/sources.list:



        $ apt-mirror-updater --list-mirrors
        -----------------------------------------------------------------------------------------------------------------------
        | Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
        -----------------------------------------------------------------------------------------------------------------------
        | 1 | http://mirror.timeweb.ru/ubuntu | Yes | No | Up to date | 6.49 KB/s |
        | 2 | http://no.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 6.38 KB/s |
        | 3 | http://ftp.aso.ee/ubuntu | Yes | No | Up to date | 5.62 KB/s |
        | 4 | http://mirror.plusserver.com/ubuntu/ubuntu | Yes | No | Up to date | 4.77 KB/s |
        | 5 | http://nl.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 4.68 KB/s |
        ...


        and then select mirror by hand:



        sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 at 14:04









        N0rbert

        19.3k54290




        19.3k54290






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1093451%2fhow-to-switch-apt-mirror-from-the-commandline%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

            How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...