Yum and Apt are great, but not flawless. I frequently encounter hiccups like “couldn’t connect to host”. Let’s troubleshoot this issue
Step 1: Check the log
First, we will look at what yum is actually doing. So perform a yum command like
yum install pip
If you encounter the issue “Another app is currently holding the yum lock; waiting for it to exit” then you need to kill the yum process. The id is listed under “State” on your screen, simply check the number “pid:”
After you run yum again, yum will fetch the CentOS baseurl defined in your CentOS-Base.repo file in /etc/yum.repos.d to connect to the main repository. If this url is different to centos.org, we can easily fix the pycurl error and make it connect to the host again.
As you can imagine, there are quite a few packages that will mess with this file or even your host may mess with this file, so all we have to do is to go into the folder and fix the baseurl.
Step 2: Fixing CentOS-Base.repo Baseurl
Go into yum.repos.d
This path works on CentOS 6/7, but may be different on other Linux distributions.
Let’s take a quick look at the file.
Ah! Here we go, the baseurl was set incorrectly, preventing your server to properly connect.
Instead of messing with this file, we are going to create a quick backup:
CTRL + X to exit
Move the file
mv CentOS-Base.repo CentOS-Base.repo.bak
Let’s fetch a fresh Base repo from Centos.org:
Go to github for the latest CentOS6 Base repo!
Don’t use wget to download that, you need to open this URL and copy/paste the content or use git to clone it.
Now paste the content.
Voilà, yum is fetching again – from the correct baseurl:
Step 3: Check Resolver.conf
Not working for you?
And comment out the existing nameservers (add two leading ##)
Then insert Google’s nameserver:
nameserver 22.214.171.124 nameserver 126.96.36.199
Voilà, yum should fetch again and you should no longer get the error “Yum couldn’t connect to host”.
Still not working? Post a comment below or in our support forums.