APT

    Looking for available versions of a package

    apt-cache policy <packageName>
    

    Install specific version of a package

    apt-get install pkgName=pkgVersion
    

    Cacher

    Config Option 1

    Change this:

    deb http://archive.ubuntu.com/ubuntu/ hardy main restricted
    

    By this:

    deb http://SERVER_CACHER_IP:3142/archive.ubuntu.com/ubuntu/ hardy main restricted
    

    Config Option 2

    /etc/apt/apt.conf.d/01proxy:

    Acquire::http::Proxy "http://SERVER_CACHER_IP:3142";
    
    apt update
    

    Pros:

    • Compare to the option 1 and 2, if the apt-cacher isn't available, it'll continue to work by downloading through official package.
    • This option is useful for a portable which isn't in same network than apt-cacher server.

    /etc/NetworkManager/dispatcher.d/99SetAptProxy:

    #!/bin/bash
    
    ip=10.0.1.13
    nc -w 1 $ip 3142
    proxy_file="/etc/apt/apt.conf.d/02local_proxy"
    if [ $? -eq 0 ]; then
        echo "Acquire::http::Proxy { Proxy \"http://$ip:3142\"; };" > $proxy_file
        echo 'Acquire::https { Proxy "false"; };' >> $proxy_file
    else
        rm -f $proxy_file
    fi
    
    chmod 755 /etc/NetworkManager/dispatcher.d/99SetAptProxy
    

    Advanced Package Tool - Server

    Change cache folder

    Note: If you would like to change just for apt-cacher, there is an option in apt-cacher.conf file. So don't remove the default cache apt archives like this.

    /etc/apt/apt.conf

    dir::cache::archives /media/usb/apt-archives
    
    rm -rf /var/cache/apt/archives
    ln -s /media/usb/apt-archives /var/cache/apt/archives
    

    Cacher

    This functionality permit to avoid download twice the same packet in a network.

    You'll need apt-cacher and apache2 package.

    WARNING: Don't mix distribution on the same apt-cacher instance (cf. don't mix ubuntu and debian). To resolve this, just start two instances on different port, with different cache directory.

    Configuration

    /etc/default/apt-cacher:

    AUTOSTART=1
    

    /etc/apt-cacher/apt-cacher.conf:

    cache_dir = /media/ext_usb_stockage/apt-archives
    group = www-data
    user = www-data
    allowed_hosts = *
    

    Note: See file to know more about option. You could for example change cache dir.

    Source

    Server

    service apt-cacher start
    

    Now server is available: http://SERVER_CACHER_IP:3142