在一些没有互联网连接的网络场景中,如果我们需要安装一些必要的工具包,比如 iperf3
,net-tools
,openss-server
等,可以提前先准备好离线安装包,拷贝到这些离线安装场景的设备上进行安装
Step1. 查看软件依赖包列表
使用以下命令查看安装 openssh-server 所需的依赖包有哪些
sudo apt-cache depends iperf3
lijun@lijun-ubuntu:~/Downloads/iperf$ sudo apt-cache depends iperf3
iperf3
Depends: libc6
Depends: libiperf0
Step2. 软件安装包下载
使用以下命令可以仅下载软件安装包,下载结果为.deb
文件
sudo apt-get download <package_name>
lijun@lijun-ubuntu:~/Downloads/iperf$ sudo apt-get download iperf3
Get:1 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 iperf3 amd64 3.9-1build1 [14.6 kB]
Fetched 14.6 kB in 1s (16.8 kB/s)
Step3. 软件依赖包递归下载
以下命令将下载 iperf3 所有必需的依赖项,并将它们保存在当前工作目录中。此命令还将在errors.txt文件中记录下载过程中所出现的错误。
代码语言:bash复制for i in $(apt-cache depends iperf3 | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done
代码语言:bash复制lijun@lijun-ubuntu:~/Downloads/test$ for i in $(apt-cache depends iperf3 | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done
Get:1 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libc6 amd64 2.35-0ubuntu3.1 [3,235 kB]
Fetched 3,235 kB in 3s (1,101 kB/s)
Get:1 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 libiperf0 amd64 3.9-1build1 [81.5 kB]
Fetched 81.5 kB in 2s (50.9 kB/s)
lijun@lijun-ubuntu:~/Downloads/test$ ls -lath
total 3.2M
-rw-rw-r-- 1 lijun lijun 386 6月 26 11:28 errors.txt
drwxrwxr-x 2 lijun lijun 4.0K 6月 26 11:28 .
drwxr-xr-x 8 lijun lijun 4.0K 6月 26 11:28 ..
-rw-r--r-- 1 root root 3.1M 7月 12 2022 libc6_2.35-0ubuntu3.1_amd64.deb
-rw-r--r-- 1 root root 80K 11月 23 2021 libiperf0_3.9-1build1_amd64.deb
lijun@lijun-ubuntu:~/Downloads/test$
Step4. 软件包的打包压缩 和 解压缩 (tar.gz)
打包压缩: tar -zcvf tar-name.tar.gz file-names
:
lijun@lijun-ubuntu:~/Downloads/test$ tar -zcvf iperf3.tar.gz *.deb
iperf3_3.9-1build1_amd64.deb
libc6_2.35-0ubuntu3.1_amd64.deb
libiperf0_3.9-1build1_amd64.deb
libsctp1_1.0.19 dfsg-1build1_amd64.deb
lksctp-tools_1.0.19 dfsg-1build1_amd64.deb
lijun@lijun-ubuntu:~/Downloads/test$ ls | grep *.tar.gz
iperf3.tar.gz
解压缩: tar -zxvf tar-name.tar.gz
:
lijun@lijun-ubuntu:~/Downloads/test$ tar -zxvf iperf3.tar.gz
iperf3_3.9-1build1_amd64.deb
libc6_2.35-0ubuntu3.1_amd64.deb
libiperf0_3.9-1build1_amd64.deb
libsctp1_1.0.19 dfsg-1build1_amd64.deb
lksctp-tools_1.0.19 dfsg-1build1_amd64.deb
lijun@lijun-ubuntu:~/Downloads/test$
Step5. 安装软件包
使用以下命令来一次性安装所有的.deb
安装包,如果软件的依赖包很多,一次性安装出错的话,这里可以考虑按照Step1 中的依赖包顺序来安装试下,同时需要按照报错信息尝试递归的安装依赖包本身所需的依赖包,比如
sudo dpkg -i *.deb
lijun@lijun-ubuntu:~/Downloads/test$ sudo dpkg -i *.deb
(Reading database ... 234250 files and directories currently installed.)
Preparing to unpack libc6_2.35-0ubuntu3.1_amd64.deb ...
Unpacking libc6:amd64 (2.35-0ubuntu3.1) over (2.35-0ubuntu3.1) ...
Selecting previously unselected package libiperf0:amd64.
Preparing to unpack libiperf0_3.9-1build1_amd64.deb ...
Unpacking libiperf0:amd64 (3.9-1build1) ...
Setting up libc6:amd64 (2.35-0ubuntu3.1) ...
dpkg: dependency problems prevent configuration of libiperf0:amd64:
libiperf0:amd64 depends on libsctp1 (>= 1.0.10 dfsg); however:
Package libsctp1 is not installed.
dpkg: error processing package libiperf0:amd64 (--install):
dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/libxcb.so.1 is not a symbolic link
Errors were encountered while processing:
libiperf0:amd64
安装libiperf0
依赖包出错,因为缺少其所需的依赖包libsctp1
,我们需要先下载安装libsctp1
及其所需的依赖包(如果缺少的话)
lijun@lijun-ubuntu:~/Downloads/test$ sudo apt-get download libsctp1
lijun@lijun-ubuntu:~/Downloads/test$ sudo dpkg -i libsctp1_1.0.19 dfsg-1build1_amd64.deb
(Reading database ... 234285 files and directories currently installed.)
Preparing to unpack libsctp1_1.0.19 dfsg-1build1_amd64.deb ...
Unpacking libsctp1:amd64 (1.0.19 dfsg-1build1) over (1.0.19 dfsg-1build1) ...
Setting up libsctp1:amd64 (1.0.19 dfsg-1build1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/libxcb.so.1 is not a symbolic link
然后就可以成功安装依赖包libiperf0
了
lijun@lijun-ubuntu:~/Downloads/test$ sudo dpkg -i libiperf0_3.9-1build1_amd64.deb
(Reading database ... 234279 files and directories currently installed.)
Preparing to unpack libiperf0_3.9-1build1_amd64.deb ...
Unpacking libiperf0:amd64 (3.9-1build1) over (3.9-1build1) ...
Setting up libiperf0:amd64 (3.9-1build1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/libxcb.so.1 is not a symbolic link
最后安装软件安装包:
代码语言:bash复制lijun@lijun-ubuntu:~/Downloads/test$ sudo dpkg -i iperf3_3.9-1build1_amd64.deb
Selecting previously unselected package iperf3.
(Reading database ... 234279 files and directories currently installed.)
Preparing to unpack iperf3_3.9-1build1_amd64.deb ...
Unpacking iperf3 (3.9-1build1) ...
Setting up iperf3 (3.9-1build1) ...
Processing triggers for man-db (2.10.2-1) ...
lijun@lijun-ubuntu:~/Downloads/test$ iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
补充
为特定架构在本地下载具有依赖项的包
上面的命令已经下载了 64 位软件包。这是因为我们是从 64 位 Ubuntu 系统下载的。
如果要下载 32 位系统的软件包,首先,使用以下命令在 Ubuntu 系统中启用您想要的架构:
sudo dpkg --add-architecture i386
如果不添加架构,则在尝试下载包时将出现以下错误消息:
E: No packages found
启用选择的架构后,运行以下命令下载特定的架构相关包
代码语言:bash复制for i in $(apt-cache depends python:i386 | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done
参考自:
https://blog.csdn.net/zgp210317/article/details/120586189