Centos安装apt-get工具(已解决报错:Failed to connect to raw.githubusercontent.com port 443: Connection refused)

本文指导如何在CentOS/RHEL中解决apt-get安装报错,涉及添加域名解析、hosts文件操作及验证安装
摘要由CSDN通过智能技术生成


在安装apt-get时遇到报错:Failed to connect to raw.githubusercontent.com port 443: Connection refused【已解决】
参考文章: How to use apt or apt-get for CentOS/RHEL

1、执行命令安装

执行以下命令安装apt-get:

# 安装命令
curl https://raw.githubusercontent.com/dvershinin/apt-get-centos/master/apt-get.sh -o /usr/local/bin/apt-get

# 赋予执行权限(权限设置为:所有者具有读、写和执行权限,组和其他用户具有读和执行权限,但没有写入权限。)
chmod 0755 /usr/local/bin/apt-get

2、出现报错

但是出现了以下报错:

[datasphere@dev-data1 ~]$ sudo curl https://raw.githubusercontent.com/dvershinin/apt-get-centos/master/apt-get.sh -o /usr/local/bin/apt-get
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

在这里插入图片描述
报错显示是因为无法连接到raw.githubusercontent.com这个域名,所以我们需要先将这个域名解析添加到Linux的/etc/hosts文件中。

3、添加域名解析

# 添加域名解析(185.199.108.133添加到文件内容末尾并使用:wq保存)
sudo vi /etc/hosts

# 使域名解析配置生效
sudo /etc/init.d/network restart

# 验证apt-get安装成功
apt-get --help

首先打开https://www.ipaddress.com/这个网址查询DNS解析,在顶部搜索框输入上述域名进行查询,然后选择DNS Resource Records中的任意一个DNS服务器地址即可,比如我们185.199.108.133
在这里插入图片描述
将上面得到的DNS地址185.199.108.133添加到/etc/hosts文件末尾:
在这里插入图片描述

4、使域名解析生效并验证apt-get安装成功

然后执行sudo /etc/init.d/network restart命令使配置生效即可。
我们可以通过apt-get --help来验证apt-get安装是否成功,如下出现相关参数解释,就说明apt-get安装成功:
在这里插入图片描述

4.1 出现Invalid option Usage: apt-get <command>的说明

为什么会出现这个报错提示呢?其实是因为apt-get工具是Ubuntu系统的,而现在我们是希望把它安装到了Centos系统中使用,因为兼容性问题出现一些问题也是正常的,不影响常用功能的使用即可。
但是,出现这个报错实际上也恰恰说明了apt-get已经安装成功,因为如果没有安装成功的话出现的报错是:-bash: apt-get: command not found
口说无凭,实践是检验真理的唯一标准。在看到网友的善意提醒之后,我又去安装验证了一遍,虽然查看帮助文档的–help、-h命令无法使用,但是apt-get的常用命令是正常的看,例如apt-get install、apt-get update等等。
在这里插入图片描述

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值