1

How can I use dkpg -i and it does not update the package if already installed.

  • You have a .deb and want to install it if not yet installed? You use dpkg to install a program, so if you call it it will install, that's what it is for. What's the use-case there? – stoney Oct 27 '22 at 11:17
  • 1
    I want to use dpkg -i to install a deb package. But I don't want to overwrite an existing installation. – Sebastian Oct 27 '22 at 11:35
  • dpkg -i will replace all the files except configs. Also depending on the package you might be asked if the configs need to be replaced or kept. What do you mean by not updating? What exactly is not updated? – mestia Oct 27 '22 at 11:54

1 Answers1

2

Given an arbitrary package file as argument, this script will install it only if the corresponding package is not already installed (in any version):

#!/bin/sh

if ! dpkg -l "$(dpkg-deb -W --showformat '${Package}:${Architecture}' "$1")" | grep -q '^ii'; then dpkg -i "$1" fi

It works by extracting the package name and architecture from the package file, and checking whether a matching package is already installed. If not, it installs it.

Stephen Kitt
  • 434,908