apt-get update only for a specific repository

48,827

Solution 1

yes, apt-get can do that, and can do it in a nice way.

  1. Append following to ~/.bash_funcs

    update-repo() {
        for source in "$@"; do
            sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}" \
            -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"    
        done
    }
    
  2. Append following to ~/.bashrc

    if [ -f $HOME/.bash_funcs ]; then
    .  $HOME/.bash_funcs
    fi
    
  3. Append following to ~/.bash_completion

    # Debian user-defined completion                             -*- shell-script -*-
    
    _ppa_lists(){
        local cur
        _init_completion || return
    
        COMPREPLY=( $( find /etc/apt/sources.list.d/ -name "*$cur*.list" \
    -exec basename {} \; 2> /dev/null ) )
        return 0
    } &&
    complete -F _ppa_lists update-repo
    
  4. Then source the files

    . ~/.bashrc
    . ~/.bash_completion
    
  5. Done and start to fire it

    update-repo <tab> <tab>
    

You can update a single ppa repository without having to update whole apt source, with implement of bash-completion.

Solution 2

If the repository is configured in a specific file in the directory /etc/apt/sources.list.d/, say myrepo.list, you can update that single repository with the command:

sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/myrepo.list" \
    -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"

Nevertheless this is not very convenient.
This can be simplified defining a bash function

update_repo() {
    sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/$1.list" \
        -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
}

so that you can simply run

update_repo myrepo

Solution 3

Y PPA Manager comes with a command line tool called update-ppa that lets you update a single PPA.

For example:

sudo update-ppa ppa:nilarimogard/webupd8

Also, when adding a PPA through Y PPA Manager, the PPA source is automatically updated (only for that PPA). In a future version, there's going to be a GUI to manually update single PPAs as well.

More information about Y PPA Manager, HERE.

Solution 4

To update a specific repository, use -o, e.g.:

apt-get update -o Dir::Etc::sourcelist=/path/to/repo.list

Here is a one-liner updating only recently added apt repository

find /etc/apt/sources.list.d -type f -name '*.list' -exec sudo apt-get update -o Dir::Etc::sourcelist="{}" ';'

It's much quicker than updating all repositories, especially during VM provisioning after adding new.

Solution 5

The -u option was added in 15.10. From 15.10 to 17.10, you could use -u to automatically update only the specific repo you are adding:

add-apt-repository -u my-ppa

The silly thing is that this option was not added to man until 18.04 (it was documented in add-apt-repository --help, however). But in 18.04, this functionality was removed! (Again, not in man, but you can see in add-apt-repository --help).

In 18.04, the update functionality was changed to always do a full apt-get update after add-apt-repository. The -u option was effectively removed. It remains there for legacy syntax, but it is always set to options.update = False. In 18.04, you do have the option of -n, --no-update, which is like the old behavior. But it's all or nothing, you cannot update a single repo since 18.04.

Share:
48,827

Related videos on Youtube

Treviño
Author by

Treviño

Updated on September 18, 2022

Comments

  • Treviño
    Treviño over 1 year

    When I add a PPA and I want to install some of its content, it is quite annoying to re-update all my apt list using apt-get update.

    Is it instead possible to only sync the content of a given repository?

    • kenorb
      kenorb over 8 years
      There is no -u on Ubuntu (15.x) Vivid as far as I can tell.
    • muru
      muru over 8 years
      @Treviño It isn't mentioned in the Wily manpage: manpages.ubuntu.com/manpages/wily/en/man1/… Is it documented elsewhere?
    • Treviño
      Treviño over 8 years
      @muru I think that has to be fixed, it's only mentioned on add-apt-repository --help. Please open a bug asking to fix the manpage.
    • wisbucky
      wisbucky about 5 years
      @Treviño @muru FYI, the -u functionality was removed since 18.04. See askubuntu.com/questions/65245/…
  • Treviño
    Treviño over 12 years
    I've checked this again, but it doesn't work if then you want to install a package that has some unresolved dependency on another repository (also in the main archive)
  • krlmlr
    krlmlr over 10 years
    Is it possible to use two sourcelist files in one apt-get update run?
  • WitchCraft
    WitchCraft over 10 years
    In Ubuntu, ~/.bash_completion resides in /etc/.bash_completion which points to /usr/share/bash-completion/bash_completion and ~/.bash_funcs resides in /usr/share/bash-completion/completions/function.
  • PyRulez
    PyRulez about 10 years
    You should package this.
  • sivaprakash
    sivaprakash almost 10 years
    Are you sure the autocompletion script is working?
  • Hunsu
    Hunsu over 9 years
    What does to source the files (. ~/.bashrc)? . is a command?
  • mchid
    mchid over 9 years
    sudo add-apt-repository ppa:webupd8team/y-ppa-manager then sudo apt-get update and finally sudo apt-get install y-ppa-manager
  • vp_arth
    vp_arth over 9 years
    @user230137, yes . is an alias for source command
  • Anwar
    Anwar over 9 years
    Ah! This is great!!
  • kevy
    kevy about 9 years
    When I hit Tab it shows update-repo _init_completion: command not found
  • Jay _silly_evarlast_ Wren
    Jay _silly_evarlast_ Wren almost 9 years
    FYI: I've used the knowledge I gained from this post to propose an option to add-apt-repository to do this automatically. code.launchpad.net/~evarlast/software-properties/support-upd‌​ate/…
  • Ciprian Tomoiagă
    Ciprian Tomoiagă over 8 years
    @Jay_silly_evarlast_Wren Great intentions! Thank you! Unfortunately the link you showed no longer works
  • Jay _silly_evarlast_ Wren
    Jay _silly_evarlast_ Wren over 8 years
    @CiprianTomoiaga It got merged, but the source is here: bazaar.launchpad.net/~evarlast/software-properties/… I'm hoping it will be in wily.
  • K. Norbert
    K. Norbert about 8 years
    I had something different in mind when I read "yes, in a nice way"
  • John Bachir
    John Bachir almost 8 years
    I think this updates everything found in /path/to
  • Roman
    Roman about 6 years
    @JohnBachir Exactly.
  • Szczepan Hołyszewski
    Szczepan Hołyszewski about 5 years
    Downvoted this answer for being a ten times overkill.
  • Sajuuk
    Sajuuk about 5 years
    can you explain what does '-' mean in sourceparts config?
  • randomness2077
    randomness2077 about 5 years
    I think '-' just a dummy way to tell sourceparts should not be used. See github.com/Debian/apt/blob/master/apt-pkg/sourcelist.cc#L313 . I could be wrong though, couldn't find a proper doc explaining the '-'.
  • dw8547
    dw8547 almost 5 years
    @funicorn, what does setting the configuration item Dir::Etc::SourceParts to "-" do/mean?