4

So in a lot of tutorials, you can see a suggestion to

apt update

which of course makes a lot of sense, and only then

apt install whatever

Why not run apt update automatically with apt install? This saves time, and just more convenient, and I believe this is the default behavior of MacOS

brew install
3
  • 2
    some people pay for their bandwidth usage. May 2, 2018 at 10:12
  • So by running this command manually before installing a package, bandwidth will not be affected?
    – Bohdan
    May 2, 2018 at 10:30
  • 1
    Of course it will, but if they have other reasons to run an update (like wanting to know if updates to something already installed is available), an update might have been run so short ago that having it done automatically again is pointless and just wastes bandwidth. May 2, 2018 at 10:39

3 Answers 3

3

Rationale

Your thinking is alright, except if:

apt-get install package

called silently before each installation:

apt-get update

That would make those updates redundant if you install more than one package.

Plus, it would significantly prolong the time for each package installation.

And it is not even feasible, because the one package could be dependent on another.


Conclusion

You need to call:

apt-get update

before any installation of packages and / or upgrade.

2
  • That would make those updates redundant if you install more than one package. - but why? I don't understand this, you mean update will run before each of the pacage, if the command like this would be run? apt install pac1 pac2 pac3 This is easily fixable. If the conclusion is just to always run it manually every time, I honestly don't get why it should not be automated.
    – Bohdan
    May 2, 2018 at 10:28
  • I agree that doing an update before each individual package is installed is silly and problematic, but this doesn't really address the idea of doing an update once before the requested set of installations. May 2, 2018 at 10:37
2

As Henrik said, apt update and apt install perform two different operations. Even if you always use apt the same way (first update, then install), that's not the case for every single person in the world.

Calling update silently before each install operation is a bad idea in the following scenarios:

  1. If someone needs to install packages one by one (maybe fetching the exit code of apt for further processing), apt would waste bandwidth.

  2. You don't need an internet connection to use install if the packages were previously downloaded, so doing an update is pointless.

  3. When using install it's possible to append a hyphen - to package's name to remove it if it's installed, so doing an update is pointless.

But, if you really want apt to behave as you want, you could:

  1. Add a function like this to your .rc file: apt-install() { apt update && apt install "${@}"; }.

  2. Propose your suggestion to apt/your distro maintainers.

  3. Modify the source code of apt. It's free software after all.

2

It's two very distinct operations, and it's not hard to imagine use cases for running update without install, so just for that reason they should be separate.

And you need an updated list of packages and dependencies before you can meaningfully decide what to install. Imagine you want to install something that depends on a fooserver, if you just use the lists you have you might not consider the fancy new fooserver that someone uploaded to the repositories a few minutes ago, that really suits your needs better.

2
  • Well I'm not suggesting to deprecate update it can stay just fine, I only suggest to call it silently every time install is called. As for the new packages available, there is an apt-cache search and google, to help out with this.
    – Bohdan
    May 2, 2018 at 10:40
  • apt-cache search only uses the locally available information, and searching the net (google are evil, don't use them) seems more complicated than just reading the package descriptions with apt show <package> (I think that functionality used to be in apt-cache if you don't have a new enough apt). May 2, 2018 at 11:37

You must log in to answer this question.

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