Monday, September 24, 2012

How to remove all repositories using zypper

If you need to remove all repositories, use this command:

zypper repos | grep Yes | cut -f3 -d '|' | sed -e "s/ //" | awk '{print "zypper rr " $1}' | bash

I would suggest first to try to see the output of the command without the last bash:

zypper repos | grep Yes | cut -f3 -d '|' | sed -e "s/ //" | awk '{print "zypper rr " $1}'


  1. This was helpful, thanks. Not sure why there isn't a zypper option to do this already.

  2. This comment has been removed by the author.

  3. In SLES 15, the addon repositories you select during installation will be automatically added to the OS repository list. I wanted to remove these repositories all at once, but looks like the Aliases contain spaces. So this neat command fails. I was unable to put quotes around the awk output. So here is what I came up with:

    for i in $(seq $(($(zypper lr | wc -l)-4))); do zypper rr 1; done

  4. This is my take on this, a variation of the above: Delete the first entry in the repo list as long as there are entries in this list. Using the XML out + filter for the closing tag of a single repository () as indicator for the existence of a repo:

    while $(zypper -x lr | grep -q '</repo>'); do zypper rr 1; done