I have an environment variable set in my (docker) centos environment:

[arman@7b33ffd8619e ~]$ echo $YUM0

Note that this also works when I prepend the echo command with sudo.

As per the centos documentation;

$YUM0-9 This is replaced with the value of the shell environment variable of the same name. If the shell environment variable does not exist, then the configuration file variable will not be replaced.

However, when I try to install anything with yum from my container I get an error message clearly indicating that the environment variable is not being picked up by yum:

[arman@7b33ffd8619e ~]$ sudo yum install less
Loaded plugins: fastestmirror
http://$YUM0/x86_64/centos/7.2.1511/base/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: $YUM0; Name or service not known"
Trying other mirror.

 One of the configured repositories failed (centos),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Disable the repository, so yum won't use it by default. Yum will then
        just ignore the repository until you permanently enable it again or use
        --enablerepo for temporary usage:

            yum-config-manager --disable centos

     4. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice

            yum-config-manager --save --setopt=centos.skip_if_unavailable=true

failure: repodata/repomd.xml from centos: [Errno 256] No more mirrors to try.
http://$YUM0/x86_64/centos/7.2.1511/base/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: $YUM0; Name or service not known"

I am running the following versions:

[arman.schwarz@7b33ffd8619e ~]$ cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
[arman.schwarz@7b33ffd8619e ~]$ yum --version

Manually modifying my .repo files in /etc/yum.repos.d to use the repository name rather than relying on the environment variable causes yum to install without issue, proving that this is not an issue with the repo itself.

Running export YUM0=yumrepo.myhost.com has no effect.

How can I make the YUM0 environment variable available to yum?

  • 3
    My kneejerk thought is that sudo is stripping it out; confirm or deny with: sudo env | grep YUM0
    – Jeff Schaller
    Commented Sep 1, 2017 at 17:02
  • 1
    (btw, running sudo echo $YUM0 is a false positive; YUM0 would be expanded before sudo ran the echo)
    – Jeff Schaller
    Commented Sep 1, 2017 at 17:03
  • @JeffSchaller I think you're right - your command returns nothing.
    – quant
    Commented Sep 1, 2017 at 17:03

3 Answers 3


By default, sudo resets the environment for commands it runs. This would include your YUM0 variable, unless you also had env_keep configured.

If you are going to run the command with sudo, run it like this:

sudo YUM0=yumrepo.myhost.com yum ...rest of the command...

This will set the value of the variable as sudo executes it.

Alternatively, if your sudo rules allow it, you could start a shell and set the variable before calling the rest of the command:

sudo sh -c "YUM0=$YUM0; yum ... rest of the command ..."

As the double-quotes will allow the inner YUM0 variable to be set to the outer (current) shell's value of YUM0.


The sudo environment, unless otherwise configured (e. g. by setting env_keep) in /etc/sudoers, will not inherit your YUM0 variable. Try:

$ sudo "export YUM0=$YUM0; yum install less"

Your shell will expand $YUM0 before sending the command chain to sudo, turning the command into e. g. export YUM0=repo.example.com; yum install less.


Just to elaborate on the other suggestions here, which explain that sudo is missing the user's environment, the sudo command does allow you to run it with your permissions using the --preserve-env switch:

sudo --preserve-env yum install less
  • I believe this is still subject to the sudoers file and whether it allows (that) env variable to be preserved/kept.
    – Jeff Schaller
    Commented Aug 5, 2021 at 18:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .