11

Is there a way to force apt-get to display yes/no prompt? A --force-yes option exists, but there seems to be no --force-prompt or similar option. If you attempt to install a package that has all dependencies already installed, it will begin installation without displaying a yes/no prompt. This can be bothersome if you want to review whether dependencies exist and which ones will be installed because you don't know if the potential dependencies are installed ahead of time.

NOTE: When does “apt-get install” ask me to confirm whether I want to continue or not? is somewhat related in that it describes under what standard conditions the prompt is displayed. I'm interested to know how to force it though.

  • 1
    "This can be bothersome if you want to review whether dependencies exist and which ones will be installed." I'm confused by this. If no dependencies are being installed, what are you reviewing? – Faheem Mitha Oct 27 '14 at 16:05
  • 2
    Interesting question. There seems to be no way to do this, short of patching apt-get with a suitable option. However, this hypothetical option does not seem very useful to me, frankly. – Faheem Mitha Oct 27 '14 at 16:20
  • @FaheemMitha My purpose for doing this is that it's a lot easier to find out what new dependencies could/will be installed using apt-get install rather than apt-cache showpkg. – user369450 Oct 27 '14 at 16:44
10

There's just no way to do this with the current implementation of apt-get, you would need to open a feature request and appeal to the maintainer. The current behavior of apt-get is that when the list of packages you implicitly declared to be installed is equal to the amount of packages that will get installed, and no other packages are affected with upgrades or breaks, apt-get presumes the user already is sure of what is going to be done, if you are not sure or want to analyze what will be done without actually installing the package, you can use Costas recommendation of -s, --simulate, --just-print, --dry-run, --recon, --no-act.

There are other tools like apt-listbugs that would analyze the versions of packages to be installed before you actually install them (in this case for bugs) and warn you.

4

The command assume yes just in case of installing one package (which initiated from command line) AND all dependencies in the system already i.e nothing to install except one asked package.

In other word "if nothing to see (no extra packages) then no prompt (nothing to ask for)".

For testing purposes you can use a key -s, --simulate, --just-print, --dry-run, --recon, --no-act

  • @cpburnz if all dependecies are installed already you will not been promted so any other packages will not been installed. – Costas Oct 27 '14 at 15:39
0

Old question, I can see, but in similar situation now. Usually I do use sudo aptitude install -P PACKAGE_NAME, what always ask before install. However now in Debian default package manager is apt|apt-get and it does not have this functionality. Of course I can still install aptitude and use it... However I have wrote small sh/bash wrapper function/script for apt-get to ask before installation. It is really raw and I wrote it as a function in my terminal.

$ f () { sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf'; read -p 'Do You want to continue (y/N): ' ans; case $ans in [yY] | [yY][eE][sS]) sudo apt-get -y install "$@";; *);; esac; }

Now, let's make it more clear:

f () {
  # Do filtered simulation - without lines contains 'Inst' and 'Conf'
  sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf';

  # Interact with user - If You want to proceed and install package(s),
  # simply put 'y' or any other combination of 'yes' answer and tap ENTER.
  # Otherwise the answer will be always not to proceed.
  read -p 'Do You want to continue (y/N): ' ans;
  case $ans in
    [yY] | [yY][eE][sS])
      # Because we said 'yes' I put -y to proceed with installation
      # without additional question 'yes/no' from apt-get 
      sudo apt-get -y install "$@";
    ;;
    *)
      # For any other answer, we just do nothing. That means we do not install
      # listed packages.
    ;;
  esac
}

To use this function as a sh/bash script simply create script file e.g. my_apt-get.sh with content (Note: listing does not contain comments, to make it a bit shorter ;-) ):

#!/bin/sh

f () {
  sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf';
  read -p 'Do You want to continue (y/N): ' ans;
  case $ans in
    [yY] | [yY][eE][sS])
      sudo apt-get -y install "$@";
    ;;
    *)

    ;;
  esac
}

f "$@"

Then put it for e.g. in ~/bin/ and make it executable with $ chmod u+x ~/bin/my_apt-get.sh. If directory ~/bin is included in your PATH variable, you will be able to execute it simply by:

$ my_apt-get.sh PACKAGE_NAME(S)_TO INSTALL

Please note:

  • The code does use sudo. If you use root account, you probably need to adjust it.
  • The code does not support shell autocompletion
  • Have no idea how the code works with shell patterns (e.g. "!", "*", "?", ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.