E: Package ‘git‘ has no installation candidate

在尝试使用`apt-get install git -y`安装git时遇到错误,提示git包不可用。解决方法是首先更新apt-get源,通过运行`apt-get update`,之后再重新尝试安装git即可成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 问题

今天在Linux上安装git如下所示:

apt-get install git -y

结果出现下列错误:

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

2. 解决方案

针对上面错误,解决方案就是升级我们的:apt-get,使用下面命令

apt-get update

Get:1 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  InRelease
Ign:1 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  InRelease
Get:2 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  Release [574 B]
Get:2 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  Release [574 B]
Get:3 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  Release.gpg [801 B]
Get:3 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  Release.gpg [801 B]
Get:4 file:/var/nvinfer-runtime-trt-repo-5.0.2-ga-cuda10.0  Packages [764 B]
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]               
Get:7 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [26.7 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1428 kB]
Get:9 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]      
Get:10 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]   
Get:11 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2320 kB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [560 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [593 kB]
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [34.4 kB]
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [2202 kB]
Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2755 kB]
Get:21 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [11.3 kB]
Get:22 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [11.4 kB]
Fetched 23.3 MB in 7s (3502 kB/s)                                              
Reading package lists... Done

然后再次安装就可以了

apt-get install git -y

3. 参考文献

解决: Linux – git: command not found

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值