apt-get离线安装

下载软件包

apt-get download ${PACKAGE}

下载依赖(只能下载直接依赖,对于依赖的依赖需要手动执行递归执行)

apt-cache depends -i ${PACKAGE} | awk '/Depends:/ {print $2}' | xargs  apt-get download

下载所有依赖

#!/bin/bash

logfile=./depends.log
ret=""
function getDepends()
{
   echo "fileName is" $1>>$logfile
   # use tr to del < >
   ret=`apt-cache depends $1|grep Depends |cut -d: -f2 |tr -d "<>"`
   echo $ret|tee  -a $logfile
}
# 需要获取其所依赖包的包
libs=$1 #包名

# download libs dependen. deep in 3
i=0
while [ $i -lt 3 ] ;
do
    let i++
    echo $i
    # download libs
    newlist=" "
    for j in $libs
    do
        added="$(getDepends $j)"
        newlist="$newlist $added"
        #只下载
        apt-get download $added
        #安装
        #apt install $added --reinstall -d -y
    done

    libs=$newlist
done

#使用方法
./<脚本名>.bash <包名>

安装

dpkg -i *.deb

参考:

https://blog.csdn.net/w123456709/article/details/104375293

https://www.jianshu.com/p/434a50c6c0ed