在使用docker容器时,有时候里边没有安装vim,敲vim命令时提示说:vim: command not found,这个时候就需要安装vim,可是当你敲apt-get install vim命令时,提示:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package vim

凉凉,找不到vim编辑器,这时候就需要敲:apt-get update

这个命令的作用是:同步 /etc/apt/sources.list/etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。等更新完毕以后再敲命令:apt-get install vim安装vim即可。

但是你会发现国内机器在更新源的索引时异常的慢,这是由于下载地址是海外地址,下载速度异常慢而且可能中断更新流程,这时候我们不得不考虑换源,相关替换命令如下:

# 备份源文件
mv /etc/apt/sources.list /etc/apt/sources.list.bak

# 清华源
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free" >> /etc/apt/sources.list
echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free" >> /etc/apt/sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list
echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free" >> /etc/apt/sources.list
echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free" >> /etc/apt/sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list
echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list

# 更新索引
apt-get update

然后就可以使用命令apt-get install vim安装vim编辑器了

End

本文标题:docker镜像内安装vim编辑器

本文链接:https://www.isisy.com/992.html

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

声明:转载请注明文章来源。

如果觉得我的文章对你有用,请随意赞赏