问题描述:
在使用 (Ubuntu 20.04.5 LTS)学习 Linux 时,想要安装 tree 命令,出现下面的报错:
root@iZwz9asjf1ddlt6fy1ebqpZ:~# apt install tree
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package tree
E: Unable to locate package tree (无法定位安装包 tree)
错误原因:出现无法定位软件包原因是因为ubuntu不同的版本对应ROS不同的版本。
简单来说:你下载的ubuntu和初始版本的不同,软件安装包没有更新到你这个ubuntu版本上,下面就讲解如果更新相关软件安装包下载源
(补充)关于安装软件包命令:
Ubuntu 在线安装是执行“apt-get install”,普通用户下,还需root的权限,“sudo apt-get install”。Fedora 下在线安装软件是“yum install”。
解决方案提示
1、找不到软件包,首先判断是否是主机正常联网。方法:可以通过ping www.baidu.com检测。如下图所示:
输入指令:ping www.baidu.com,就会冒出下面的检测
root@iZwz9asjf1ddlt6fy1ebqpZ:~# ping www.baidu.com
PING www.a.shifen.com (183.2.172.185) 56(84) bytes of data.
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=1 ttl=50 time=7.64 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=2 ttl=50 time=7.64 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=3 ttl=50 time=7.62 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=4 ttl=50 time=7.65 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=5 ttl=50 time=7.68 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=6 ttl=50 time=7.65 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=7 ttl=50 time=7.66 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=8 ttl=50 time=7.66 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=9 ttl=50 time=7.64 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=10 ttl=50 time=7.65 ms
如果连不上网,想办法连上网。
2、其次,这个问题是改变了“下载源”,没有更新的原因,在命令窗口执行如下命令:
输入指令:sudo apt-get update,就会冒出下面一堆指令
root@iZwz9asjf1ddlt6fy1ebqpZ:~# sudo apt-get update
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease [265 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease [128 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports InRelease [128 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease [128 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 Packages [970 kB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main i386 Packages [718 kB]
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main Translation-en [506 kB]
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 c-n-f Metadata [29.5 kB]
Get:9 http://mirrors.cloud.aliyuncs.com/ubuntu focal/restricted amd64 Packages [22.0 kB]
Get:10 http://mirrors.cloud.aliyuncs.com/ubuntu focal/restricted i386 Packages [8,112 B]
Get:11 http://mirrors.cloud.aliyuncs.com/ubuntu focal/restricted Translation-en [6,212 B]
Get:12 http://mirrors.cloud.aliyuncs.com/ubuntu focal/restricted amd64 c-n-f Metadata [392 B]
Get:13 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe i386 Packages [4,642 kB]
Get:14 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 Packages [8,628 kB]
Get:15 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe Translation-en [5,124 kB]
Get:16 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]
Get:17 http://mirrors.cloud.aliyuncs.com/ubuntu focal/multiverse amd64 Packages [144 kB]
Get:18 http://mirrors.cloud.aliyuncs.com/ubuntu focal/multiverse i386 Packages [74.7 kB]
Get:19 http://mirrors.cloud.aliyuncs.com/ubuntu focal/multiverse Translation-en [104 kB]
Get:20 http://mirrors.cloud.aliyuncs.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9,136 B]
Get:21 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main i386 Packages [1,024 kB]
Get:22 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 Packages [3,534 kB]
Get:23 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main Translation-en [547 kB]
Get:24 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 c-n-f Metadata [17.7 kB]
Get:25 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/restricted amd64 Packages [3,200 kB]
Get:26 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/restricted i386 Packages [39.6 kB]
Get:27 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/restricted Translation-en [448 kB]
Get:28 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [548 B]
Get:29 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe amd64 Packages [1,229 kB]
Get:30 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe i386 Packages [807 kB]
Get:31 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe Translation-en [294 kB]
Get:32 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [28.0 kB]
Get:33 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/multiverse i386 Packages [8,440 B]
Get:34 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/multiverse amd64 Packages [27.1 kB]
Get:35 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/multiverse Translation-en [7,936 B]
Get:36 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [616 B]
Get:37 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/main amd64 Packages [45.7 kB]
Get:38 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/main i386 Packages [36.1 kB]
Get:39 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/main Translation-en [16.3 kB]
Get:40 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/main amd64 c-n-f Metadata [1,420 B]
Get:41 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]
Get:42 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/universe amd64 Packages [25.0 kB]
Get:43 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/universe i386 Packages [13.8 kB]
Get:44 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/universe Translation-en [16.3 kB]
Get:45 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [880 B]
Get:46 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Get:47 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main i386 Packages [807 kB]
Get:48 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main amd64 Packages [3,166 kB]
Get:49 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main Translation-en [469 kB]
Get:50 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main amd64 c-n-f Metadata [14.3 kB]
Get:51 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/restricted amd64 Packages [3,082 kB]
Get:52 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/restricted i386 Packages [38.3 kB]
Get:53 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/restricted Translation-en [431 kB]
Get:54 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [548 B]
Get:55 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/universe amd64 Packages [1,009 kB]
Get:56 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/universe i386 Packages [680 kB]
Get:57 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/universe Translation-en [213 kB]
Get:58 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/universe amd64 c-n-f Metadata [21.2 kB]
Get:59 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/multiverse i386 Packages [7,204 B]
Get:60 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/multiverse amd64 Packages [24.8 kB]
Get:61 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/multiverse Translation-en [5,968 B]
Get:62 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Fetched 43.2 MB in 8s (5,420 kB/s)
Reading package lists... Done
显示 ”Reading package lists… Done“ 即软件安装包更新成功
然后安装 tree命令安装包,即可安装成功
root@iZwz9asjf1ddlt6fy1ebqpZ:~# apt install tree
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
tree
0 upgraded, 1 newly installed, 0 to remove and 49 not upgraded.
Need to get 43.0 kB of archives.
After this operation, 115 kB of additional disk space will be used.
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 tree amd64 1.8.0-1 [43.0 kB]
Fetched 43.0 kB in 0s (331 kB/s)
Selecting previously unselected package tree.
(Reading database ... 115898 files and directories currently installed.)
Preparing to unpack .../tree_1.8.0-1_amd64.deb ...
Unpacking tree (1.8.0-1) ...
Setting up tree (1.8.0-1) ...
Processing triggers for man-db (2.9.1-1) ...
下面就可以使用 tree 功能将文件树,图形化显示出来了:
1、我在当前目录下创建一串 text 文件
2、使用 tree
root@iZwz9asjf1ddlt6fy1ebqpZ:~/text# mkdir -p text1/text2/text3/text4/
root@iZwz9asjf1ddlt6fy1ebqpZ:~/text# tree .
.
└── text1
└── text2
└── text3
└── text4
注:
本文参考了这个文章 Ubuntu 20.04.5 LTS报错
在此基础上加入自己的一些解释