Tag Archives: zypper

Equivalent of `apt autoremove` for zypper (or removing unneeded packages using zypper)

zypper pa --unneeded | grep '^i' | cut -d\| -f3 | xargs sudo zypper -n remove
  • zypper pa --unneeded lists unneeded packages.
  • grep '^i' selects lines that starts with i (installed package)
  • cut d\| -f3 selects third field after cutting line at delimited |
  • And the last one runs sudo zypper -n remove on the output.

On older version of zypper, following script may be useful.

https://github.com/dilawar/Scripts/blob/master/zypper_autoremove.sh

Using zypper inside Dockerfile in non-interactive mode (without user prompts)

zypper is not the most container-friendly package manager out there. There is a --non-interactive global option that silences the prompts and assumes suitable defaults, but it doesn’t always work, for example, when you add a repository and import the keys. See more here

How to use zypper in bash scripts for someone coming from apt-get?

Following works for me and I use this pattern in all of my openSUSE based containers.

FROM opensuse/leap:15.4

RUN zypper --non-interactive --quiet addrepo --refresh  \
    https://download.opensuse.org/repositories/devel:languages:rust/15.4/devel:languages:rust.repo
RUN zypper --non-interactive --gpg-auto-import-keys refresh
RUN zypper --non-interactive install \
    --allow-vendor-change \
    osc obs-service-cargo_vendor obs-service-recompress obs-service-tar_scm \
    && zypper clean --all

This is based on the following answer.

How to use zypper in bash scripts for someone coming from apt-get?