Ubuntu – apt-get update only for a specific repository

aptpackage-managementsoftware-sources

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?

Best Answer

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.

Related Question