当无法直接用apt instll时,Linux如何离线安装软件包(以make为例)

诸神缄默不语-个人技术博文与视频目录

(如果直接用root登录的,以下命令就不用加sudo)

我实际上用的系统是WSL,发行版是Ubuntu 20.04.3 LTS

当运行make setup时,出现以下信息:

plain 复制代码
Command 'make' not found, but can be installed with:

sudo apt install make        # version 4.2.1-1.2, or
sudo apt install make-guile  # version 4.2.1-1.2

如果网络正常就可以直接执行sudo apt install make命令;但显然我网络不行,报错信息如下:

plain 复制代码
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  make-doc
The following NEW packages will be installed:
  make
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 162 kB of archives.
After this operation, 393 kB of additional disk space will be used.
Err:1 http://archive.ubuntu.com/ubuntu focal/main amd64 make amd64 4.2.1-1.2
  Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::101). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2a06:bc80:0:1000::17). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::103). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::102). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2a06:bc80:0:1000::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::103). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::102). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2a06:bc80:0:1000::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::101). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (185.125.190.81), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.82), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.83), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.82), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.81), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.22), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.24), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.83), connection timed out
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/m/make-dfsg/make_4.2.1-1.2_amd64.deb  Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::101). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2a06:bc80:0:1000::17). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::103). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::102). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2a06:bc80:0:1000::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::103). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::102). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2a06:bc80:0:1000::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::101). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (185.125.190.81), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.82), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.83), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.82), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.81), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.22), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.24), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.83), connection timed out
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

有一种解决思路是在apt的配置环境里增加镜像源。但是我不知道为啥配了也没用,所以我就直接去离线下载安装了。

乌班图软件包网址:Ubuntu -- Ubuntu Packages Search

如果你的Ubuntu系统版本比较高,就在这些发布版中,可以直接用首页的搜索找你需要的包(其实我的版本不能,所以后面会有介绍如何找历史releases的内容):

这个发布版代号跟实际的Ubuntu版本号(可以通过lsb_release -a命令拿到)的对应关系可以见Ubuntu releases网址:Ubuntu Releases

以 jammy (22.04LTS) 为例:

在这里需要先安装依赖的libc6包(如果不知道有没有安装也可以先安装make,后文会介绍如何根据提醒安装所需的包的),然后根据硬件架构选择对应的软件包。

一般个人电脑不是amd64就是arm64,这个如何看呢,就运行hostnamectl命令,如果architecture是x86-64,就是amd64(WSL一般都是);如果是aarch64arm64,就是arm64:

然后从这一堆链接里下你能下的(我一般用亚洲第一个,就是kr那个):

(另外在这里页面还推荐修改apt镜像源,如果想那么干的话照着改就得了。需要注意这个文件需要用管理员权限编辑,所以记得加sudo。但是反正我实测无效,不知道为什么......)

把这个deb文件下载下来以后,在WSL中执行命令:

bash 复制代码
sudo dpkg -i /path/make_4.4.1-2_amd64.deb

最后那个换成你下载的deb文件的路径

如果版本依赖有问题,会报错:

plain 复制代码
Selecting previously unselected package make.
(Reading database ... 32223 files and directories currently installed.)
Preparing to unpack .../path/make_4.4.1-2_amd64.deb ...
Unpacking make (4.4.1-2) ...
dpkg: dependency problems prevent configuration of make:
 make depends on libc6 (>= 2.38); however:
  Version of libc6:amd64 on system is 2.31-0ubuntu9.2.

dpkg: error processing package make (--install):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.9.1-1) ...
Errors were encountered while processing:
 make

我们再来查看需要下载老版本的情况。实际上我们查看一开始的报错信息就能看到其实已经给我们指定了应该下的版本(也就是4.2.1-1.2)。在前面的下载页面中我们也很容易找到这句话:您可以从以下任意站点的 pool/main/m/make-dfsg/ 子目录中下载所需的文件

在历史releases:https://old-releases.ubuntu.com/ 中,打开ubuntu子文件夹(根据下载页面直接猜类似的布局也能看出来):https://old-releases.ubuntu.com/ubuntu/

从这里就进入下载页面里的子目录https://old-releases.ubuntu.com/ubuntu/pool/main/m/make-dfsg/ 中,很快就能找到所需deb文件:

判断硬件架构和离线安装deb文件的方式跟之前一样,不再赘述。

安装成功的打印内容:

plain 复制代码
[sudo] password for user_name:
dpkg: warning: downgrading make from 4.4.1-2 to 4.2.1-1.2
(Reading database ... 32241 files and directories currently installed.)
Preparing to unpack .../path/make_4.2.1-1.2_amd64.deb ...
Unpacking make (4.2.1-1.2) over (4.4.1-2) ...
Setting up make (4.2.1-1.2) ...
Processing triggers for man-db (2.9.1-1) ...

参考资料:Ubuntu 离线安装软件包 | 人人都懂物联网

相关推荐
Sivan_Xin2 小时前
拒绝 If-Else 屎山:利用适配器模式(Adapter)构建第三方登录的“防腐层”实战
linux·python·适配器模式
learning-striving2 小时前
kali默认桌面Xfce切换为GNOME桌面
linux·运维·服务器·kali
源远流长jerry2 小时前
dpdk之kni处理dns案例
linux·网络·网络协议·ubuntu·ip
黄昏晓x2 小时前
Linux----进程控制
android·linux·运维
郝亚军2 小时前
ubutnu 64位系统,需要安装的工具包
linux·运维·ubuntu
宇钶宇夕2 小时前
CoDeSys入门实战一起学习(二十八):(ST)三台电机顺起逆停程序详解
运维·学习·自动化·软件工程
EmbedLinX2 小时前
嵌入式Linux C++常用设计模式
linux·c++·设计模式
萧曵 丶2 小时前
Nginx 高频面试题(含答案)
运维·nginx
Bear on Toilet2 小时前
腾讯云服务器开放UDP端口操作手册_2026最新
服务器·udp·腾讯云