> CentOS > CentOS故障 >

vim 时出现 -bash: vim: command not found解决

用centos 的主机的時候, 用 vim 时出现 -bash: vim: command not found. 只能使用 vi. 那么如何安裝 vim 呢?
输入 rpm -qa|grep vim 命令, 如果 vim 已经正确安装,会返回下面的三行代码:
[root@centos]# rpm -qa |grep vim          
vim-minimal-7.0.109-6.el5
vim-common-7.0.109-7.2.el5
vim-enhanced-7.0.109-7.2.el5
 
如果少了其中的某一条,比如 vim-enhanced 的,就用命令 yum -y install vim-enhanced 来安装:
yum -y install vim-enhanced
如果上面的三条都沒有返回, 可以直接用 yum -y install vim* 命令
yum -y install vim*
 
 
二。
[root@localhost ~]# ll
#部分省略了......
-rwxr--r-- 1 root root    34 Apr 26 12:48 test.txt
#用vim打开test.txt文件 
[root@localhost ~]# vim test.txt
-bash: vim: command not found
[root@localhost ~]# 
#使用命令查询 
[root@localhost ~]# rpm -qa | grep vim
vim-minimal-7.0.109-6.el5
#发现只有这个包,说明没安装完整,需要重新安装vim
#下面是安装过程
[root@localhost ~]# yum install -y vim*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 
 * addons: mirrors.grandcloud.cn
 * base: mirrors.grandcloud.cn
 * extras: mirrors.grandcloud.cn
 * updates: mirrors.grandcloud.cn
 
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vim-X11.x86_64 2:7.0.109-7.2.el5 set to be updated
---> Package vim-common.x86_64 2:7.0.109-7.2.el5 set to be updated
---> Package vim-enhanced.x86_64 2:7.0.109-7.2.el5 set to be updated
---> Package vim-minimal.x86_64 2:7.0.109-7.2.el5 set to be updated
--> Finished Dependency Resolution
 
Dependencies Resolved
 
========================================================================================
 Package               Arch            Version                      Repository     Size
========================================================================================
Installing:
 vim-X11               x86_64          2:7.0.109-7.2.el5            base          1.0 M
 vim-common            x86_64          2:7.0.109-7.2.el5            base          6.4 M
 vim-enhanced          x86_64          2:7.0.109-7.2.el5            base          1.3 M
Updating:
 vim-minimal           x86_64          2:7.0.109-7.2.el5            base          334 k
 
Transaction Summary
========================================================================================
Install       3 Package(s)
Upgrade       1 Package(s)
 
Total download size: 9.1 M
Downloading Packages:
(1/4): vim-minimal-7.0.109-7.2.el5.x86_64.rpm                    | 334 kB     00:00     
(2/4): vim-X11-7.0.109-7.2.el5.x86_64.rpm                        | 1.0 MB     00:03     
(3/4): vim-enhanced-7.0.109-7.2.el5.x86_64.rpm                   | 1.3 MB     00:03     
(4/4): vim-common-7.0.109-7.2.el5.x86_64.rpm                     | 6.4 MB     00:21     
----------------------------------------------------------------------------------------
Total                                                   314 kB/s | 9.1 MB     00:29     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : vim-common                                                       1/5 
  Installing     : vim-X11                                                          2/5 
  Updating       : vim-minimal                                                      3/5 
  Installing     : vim-enhanced                                                     4/5 
  Cleanup        : vim-minimal                                                      5/5 
 
Installed:
  vim-X11.x86_64 2:7.0.109-7.2.el5            vim-common.x86_64 2:7.0.109-7.2.el5      
  vim-enhanced.x86_64 2:7.0.109-7.2.el5      
 
Updated:
  vim-minimal.x86_64 2:7.0.109-7.2.el5                                                  
 
Complete!
#安装成功 
[root@localhost ~]#  
[root@localhost ~]# vim test.txt 
#进入vim操作界面 
#:q退出界面后,使用命令查看 
[root@localhost ~]# rpm -qa | grep vim
vim-enhanced-7.0.109-7.2.el5
vim-common-7.0.109-7.2.el5
vim-X11-7.0.109-7.2.el5
vim-minimal-7.0.109-7.2.el5
(责任编辑:IT)