Enable Proxy Settings for Yum Command on CentOS 7

enable proxy settings for yum command on centos 7
enabling proxy settings for yum command on centos

In this article, we will show you how to enable proxy settings for yum command on CentOS 7. Yum is a package management tool that works with RPM packages. It is available on RedHat Enterprise Linux, CentOS, and older versions of Fedora, and it is the most convenient way to handle OS packages and their dependencies on these operating systems.

When a server can only be accessed through proxy servers, you need to configure yum to use a proxy server so you can install a RPM package, or update the currently installed yum packages.
To configure a proxy server so the system user can access and use yum commands is a fairly easy and straight-to-the-point task, and it shouldn’t take more than 5 minutes to configure it. Let’s get started.

1. Configure proxy settings

Edit the ‘/etc/yum.conf’ yum configuration file and specify the proxy settings in the main section e.g.:

[main]

proxy=http://proxysever.yourdomain.com:3128
proxy_username=rhproxy
proxy_password=D5znQs4P8Rmtw

tolerant=1
errorlevel=1
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

Where:

  • proxy is the Proxy server URL (domain name or IP address) that yum should use including the TCP port number. In this example, proxysever.yourdomain.com is the URL of the proxy server. Do not forget to change 3128 with the actual port number of the proxy server.
  • proxy_username is the proxy server username to use for the proxy URL. If this is unset it inherits it from the global setting.
  • proxy_password is the proxy server password to use for the proxy URL. If this is unset it inherits it from the global setting.

Make sure to use a strong password for the proxy password. Use a password that is not the same as any other system user password, especially the root user password.

Please note that all users should have read access to /etc/yum.conf file so they can connect to the proxy server with those details when using yum commands.

2. Enable proxy access for a specific system user only

If for some reason you want to enable proxy access only for a specific system user, you need to add these lines to the user’s shell profile:

http_proxy="http://proxysever.yourdomain.com:3128"
export http_proxy
setting up proxy settings for yum command on centos

If the user is using the default bash shell, the user profile should be set in ~/.bash_profile file. The settings we used in this example should enable yum to use the proxy server proxysever.yourdomain.com, connecting to port 3128.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

If the proxy server requires a username and password, edit the user’s shell profile and add the username and password to the URL of the proxy server:

http_proxy="http://rhproxy:D5znQs4P8Rmtw@proxysever.yourdomain.com:3128"
export http_proxy

Do not forget to replace rhproxy, D5znQs4P8Rmtw, proxysever.yourdomain.com and 3128 with the actual proxy username, proxy user password, proxy URL and the port number of the proxy server respectively.

3. Test the settings

In order to check if proxy settings are configured properly, run some yum command, for example, try to use:

yum clean all && yum search dovecot

The output of this command will show you a list with details of all available packages named dovecot:

# yum search dovecot
=========================================================================== N/S matched: dovecot ============================================================================
dovecot-devel.x86_64 : Development files for dovecot
dovecot-mysql.x86_64 : MySQL back end for dovecot
dovecot-pgsql.x86_64 : Postgres SQL back end for dovecot
dovecot-pigeonhole.x86_64 : Sieve and managesieve plug-in for dovecot
dovecot.i686 : Secure imap and pop3 server
dovecot.x86_64 : Secure imap and pop3 server

  Name and summary matches only, use "search all" for everything.

Congratulations. You have successfully configured proxy server for yum command on CentOS 7.


how to enable proxy settings for yum command on centos 7

Of course, you don’t have to enable proxy settings for yum command on CentOS 7, if you use one of our Managed CentOS VPS Hosting Solutions, in which case you can simply ask our expert Linux admins to configure the use of a proxy server so you can use yum command for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to enable proxy settings for yum command on CentOS 7,  please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment