docker容器实例安装Vim编辑器报错Unable to locate package vim
问题重现
当想要在Docker容器使用中使用vim编辑器时,发现没有,而且也没有vi。然后想用yum安装vim时,发现yum没有。
解决方案
原因:因为linux不同的发行版使用的软件包管理工具不一样,使用的不同的发行版软件包的源也有区别
-
查看docker容器实例是什么发行版本
-
cat /etc/os-release
-
-
如果是Ubuntu的发行版,查看对应的Code name
-
https://wiki.ubuntu.com/Releases官网可以查询Ubuntu的发行版本号对应的Code name
-
根据对应的版本找到对应的Code name是否和自己发行版是否一样
-
-
更新Code name相对应的源(至于为什么Unbuntu更换源需要注意Code name,因为Ubuntu的每个版本的源对应一个Code name)
- 备份原始的源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
- 更新为官方源(二选一)
echo -e "deb http://archive.ubuntu.com/ubuntu/ focal main restricted\ndeb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted\ndeb http://archive.ubuntu.com/ubuntu/ focal universe\ndeb http://archive.ubuntu.com/ubuntu/ focal-updates universe\ndeb http://archive.ubuntu.com/ubuntu/ focal multiverse\ndeb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse\ndeb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse\ndeb http://security.ubuntu.com/ubuntu/ focal-security main restricted\ndeb http://security.ubuntu.com/ubuntu/ focal-security universe\ndeb http://security.ubuntu.com/ubuntu/ focal-security multiverse\n">/etc/apt/sources.list
- 更新为163源(二选一)
echo -e "deb https://mirrors.163.com/ubuntu/ focal main restricted universe multiverse\ndeb https://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse\ndeb https://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse\ndeb https://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse">/etc/apt/sources.list
-
安装vim(但是还是不能安装 yum)
apt update apt install vim
注意这里是介绍Ubuntu更换源,Centos系类的发行版更换源的文件名不同
参考博客
(2条消息) docker ubuntu 使用apt安装vim–报错Unable to locate package vim_onlyoneya的博客-CSDN博客