安装git提示 E: Package ‘git’ has no installation candidate:



问题描述

Linux系统(Ubuntu 18.04.3 )中使用apt工具安装git工具时出现 E: Package ‘git‘ has no installation candidate 问题:

E: Package 'git' has no installation candidate
root@interactive17068:~# apt-get install git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package git 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 'git' has no installation candidate


解决方案

以下三个原因可能导致安装失败:

原因一

解决方法:在非root用户下安装,权限不够,非root用户的话建议加上sudo:

sudo apt-get install git

原因二

解决方法:由于系统中的apt包版本过低需要更新之后在安装git,依次输入如下两句:

apt-get update
apt-get install git

原因三

Ubuntu 默认使用的官方源的服务器从国内访问速度很慢。可以在装完 Ubuntu 系统后最好把官方源更换为国内的源。安装源出现问题也可能导致apt工具更新过程中出现问题,所以可以通过命令修改系统中的源文件来增加不同的下载源:

(1)查看系统版本

可以通过此命令查看自己系统的版本:

lsb_release -a

(2)修改源文件

修改/etc/apt内的sources.list文件来增加或修改安装源:
提示:在修改之前可以对源文件进行备份以便于修改出错时可以恢复

vim /etc/apt/sources.list

(3)增加国内源

这里给出了了一些经常使用的国内源可根据需要自行添加:

# 清华大学源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# 阿里云源(推荐)
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

总结

以上就是安装git提示E: Package ‘git‘ has no installation candidate 的解决方法。

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐