安装Ubuntu后首次使用vim编辑器时,输入命令vim hello.sh
,出现以下报错:
The program 'vim' can be found in the following packages:
* vim
* vim-gnome
* vim-tiny
* vim-athena
* vim-athena-py2
* vim-gnome-py2
* vim-gtk
* vim-gtk-py2
* vim-gtk3
* vim-gtk3-py2
* vim-nox
* vim-nox-py2
Try: apt install <selected package>
说明:系统还未安装vim编辑器,且vim的安装包已经有了,在列出的这些包里,可以用sudo apt-get install vim-gtk
命令来安装,
输入Y继续安装
若出现:
nigel@yq-ubuntu:~/worksp$ sudo apt-get install vim-gtk
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package vim-gtk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘vim-gtk’ has no installation candidate
这种情况如果你没有出现说明你的软件源设置是可以的,我的刚装好没有选择软件源就会出现这个提示,找不到这个包。这时,我们应该在software center中找到software sources(软件源设置),点击Ubuntu software->找到download from点击进去选择other…->select best server ,然后他会自动寻找适合你IP的最佳软件源,静静等待。找到之后,chooes server退出即可。
3.我们再次回到终端,执行sudo apt-get update更新一下
4.然后我们再次执行sudo apt-get install vim-gtk,
这次发现还是没有成功,而是出现了下面这种情况:
nigel@yq-ubuntu:~/worksp$ sudo apt-get install vim-gtk
Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
vim-gtk : Depends: vim-common (= 2:7.3.429-2ubuntu2) but 2:7.3.429-2ubuntu2.1 is to be installed
E: Unable to correct problems, you have held broken packages.
原因可能是安装vim所依赖的vim-common和系统自带的vim-common版本冲突,解决办法就是先把vim-common卸载了然后再安装vim即可。
5.执行这句话sudo apt-get remove vim-common 卸载vim-common
6.再次执行sudo apt-get install vim-gtk,这次会发现成功了!!!
输入 sudo apt-get install vim,结果又出现以下提示:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package vim is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package vim has no installation candidate
Google一下,发现好像是缺少某些包,要更新软件源。解决方法如下:
把/etc/apt/sources.list 里的软件源列表修改一下。
步骤:
首先,安全起见,先备份一下要修改的文件。命令:cp -i /etc/apt/sources.list /etc/apt/sources.list_backup
然后,打开sources.list, 看他们是用nano编辑器打开的,我也就照搬了,命令:sudo nano /etc/apt/sources.list
打开之后,可以根据自己的情况看这个网页的说明 http://ubuntuguide.org/wiki/Ubuntu:Lucid#Add_Extra_Repositories 修改,按Ctrl+X 退出。
然后,更新一下。 命令:sudo apt-get update
更新后,再执行 sudo apt-get install vim, 系统就会自动下载缺少的包,然后vim就可以顺利安装了。
ubuntu14.10默认的vim版本是vim-tiny,想要用的话就在终端输入vim.tiny
vim-tiny简化版的,不是很好用,建议卸载后安装完全版vim
卸载自带vim命令:apt-get autoremove vim-common
安装vim命令:apt-get install vim