E: Unable to locate package vim 的解决方案---docker 镜像下安装Vim

    xiaoxiao2025-08-03  26

    1 问题介绍

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

    root@1b4671904bfa:/# apt-get install vim Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package vim

     

    2 问题解决

    2.1 配置国内镜像源

    实际在使用过程中,运行 apt-get update,然后执行 apt-get install -y vim,下载地址由于是海外地址,下载速度异常慢而且可能中断更新流程,所以做下面配置:

    root@1b4671904bfa:/# mv /etc/apt/sources.list /etc/apt/sources.list.bak root@1b4671904bfa:/# echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list root@1b4671904bfa:/# echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list root@1b4671904bfa:/# echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list root@1b4671904bfa:/# echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

     

    2.2 执行更新和安装命令 

    root@1b4671904bfa:/# apt-get update Ign:1 http://mirrors.163.com/debian jessie InRelease Get:2 http://mirrors.163.com/debian jessie-proposed-updates InRelease [139 kB] Get:3 http://mirrors.163.com/debian jessie Release [148 kB] Hit:4 http://repo.mysql.com/apt/debian stretch InRelease Get:5 http://mirrors.163.com/debian jessie Release.gpg [2420 B] Get:6 http://mirrors.163.com/debian jessie-proposed-updates/main Sources [1036 B] Get:7 http://mirrors.163.com/debian jessie-proposed-updates/main amd64 Packages [720 B] Get:8 http://mirrors.163.com/debian jessie/contrib Sources [50.4 kB] Get:9 http://mirrors.163.com/debian jessie/non-free Sources [99.2 kB] Get:10 http://mirrors.163.com/debian jessie/main Sources [7063 kB] Get:11 http://mirrors.163.com/debian jessie/non-free amd64 Packages [83.2 kB] Get:12 http://mirrors.163.com/debian jessie/main amd64 Packages [6818 kB] Get:13 http://mirrors.163.com/debian jessie/contrib amd64 Packages [49.8 kB] Fetched 14.5 MB in 9s (1543 kB/s) Reading package lists... Done root@1b4671904bfa:/# apt-get install -y vim Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: vim-common vim-runtime Suggested packages: ctags vim-doc vim-scripts The following NEW packages will be installed: vim vim-common vim-runtime 0 upgraded, 3 newly installed, 0 to remove and 4 not upgraded. Need to get 6185 kB of archives. After this operation, 28.9 MB of additional disk space will be used. Get:1 http://mirrors.163.com/debian jessie/main amd64 vim-common amd64 2:7.4.488-7+deb8u3 [185 kB] Get:2 http://mirrors.163.com/debian jessie/main amd64 vim-runtime all 2:7.4.488-7+deb8u3 [5048 kB] Get:3 http://mirrors.163.com/debian jessie/main amd64 vim amd64 2:7.4.488-7+deb8u3 [953 kB] Fetched 6185 kB in 4s (1308 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package vim-common. (Reading database ... 8735 files and directories currently installed.) Preparing to unpack .../vim-common_2:7.4.488-7+deb8u3_amd64.deb ... Unpacking vim-common (2:7.4.488-7+deb8u3) ... Selecting previously unselected package vim-runtime. Preparing to unpack .../vim-runtime_2:7.4.488-7+deb8u3_all.deb ... Adding 'diversion of /usr/share/vim/vim74/doc/help.txt to /usr/share/vim/vim74/doc/help.txt.vim-tiny by vim-runtime' Adding 'diversion of /usr/share/vim/vim74/doc/tags to /usr/share/vim/vim74/doc/tags.vim-tiny by vim-runtime' Unpacking vim-runtime (2:7.4.488-7+deb8u3) ... Selecting previously unselected package vim. Preparing to unpack .../vim_2:7.4.488-7+deb8u3_amd64.deb ... Unpacking vim (2:7.4.488-7+deb8u3) ... Setting up vim-common (2:7.4.488-7+deb8u3) ... Setting up vim-runtime (2:7.4.488-7+deb8u3) ... Processing /usr/share/vim/addons/doc Setting up vim (2:7.4.488-7+deb8u3) ... update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode update-alternatives: warning: skip creation of /usr/share/man/fr/man1/vi.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group vi) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/it/man1/vi.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group vi) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/pl/man1/vi.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group vi) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ru/man1/vi.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group vi) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ja/man1/vi.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group vi) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/man1/vi.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group vi) doesn't exist update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode update-alternatives: warning: skip creation of /usr/share/man/fr/man1/view.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group view) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/it/man1/view.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group view) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/pl/man1/view.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group view) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ru/man1/view.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group view) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ja/man1/view.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group view) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/man1/view.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group view) doesn't exist update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode update-alternatives: warning: skip creation of /usr/share/man/fr/man1/ex.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group ex) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/it/man1/ex.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group ex) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/pl/man1/ex.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group ex) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ru/man1/ex.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group ex) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ja/man1/ex.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group ex) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/man1/ex.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group ex) doesn't exist update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto mode update-alternatives: warning: skip creation of /usr/share/man/fr/man1/editor.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group editor) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/it/man1/editor.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group editor) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/pl/man1/editor.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group editor) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ru/man1/editor.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group editor) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/ja/man1/editor.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group editor) doesn't exist update-alternatives: warning: skip creation of /usr/share/man/man1/editor.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group editor) doesn't exist

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

    到此,vim命令安装成功! 

    最新回复(0)