57

How do I install multiple packages?

For example, I want to install both package X and Package Y, I know that this is not possible by default but is there any alternate way of doing this or Can I atleast queue them for installation?

BeginnersSake
  • 749
  • 1
  • 7
  • 15
  • 1
    haven't you noticed any tutorial that has `apt-get install p1 p2 p3`? – Aloha Jan 22 '17 at 10:37
  • 1
    Possible duplicate of [How to make a package manager wait if another instance of APT is running?](https://askubuntu.com/questions/132059/how-to-make-a-package-manager-wait-if-another-instance-of-apt-is-running) – mniess Oct 20 '17 at 11:56
  • @mniess: see above – David Foerster Oct 21 '17 at 07:09
  • This question might have some useful answers: [How to make a package manager wait if another instance of APT is running?](https://askubuntu.com/q/132059/301745) – wjandrea Oct 21 '17 at 15:52
  • @DavidFoerster You're right. I've replaced my comment. – wjandrea Oct 21 '17 at 15:53
  • @DavidFoerster well, the correct answer is "you can't" because only one program can have the lock on dpkg. The linked answer is the closest you can get to the desired behavior. – mniess Oct 21 '17 at 17:23
  • @mniess OP has already accepted an answer, which is about simply giving multiple arguments to `apt-get`. So OP's not looking to install two packages in parallel, just queue them. – wjandrea Oct 21 '17 at 17:47
  • @mniess: You misunderstood the question. See the accepted answer. OP's comment on it does point to your suggestion though. – David Foerster Oct 21 '17 at 17:50
  • OP asked for installing *"at the same time"* and not sequentially and their question looks like that's what they actually want. So I really don't think I misunderstood the question. @DavidFoerster – mniess Oct 21 '17 at 17:58
  • @mniess: The question hinges on what OP means with "at the same time". Does it mean "in a single command" (since "to install a package" means "to issue a command to install a package" in this context) or "in parallel". Considering the accepted answer I tend towards the former. – David Foerster Oct 21 '17 at 19:51
  • @DavidFoerster You said it yourself. Their comment on the accepted answer clearly indicates they wanted "in parallel". – mniess Oct 22 '17 at 13:12
  • 1
    @mniess: And the comment on the comment clearly explains why that is a different question from the wording of the original question. – David Foerster Oct 22 '17 at 18:47
  • 1
    @mniess My question might have led to confusion. But the answer kind of solved my problem. I have edited the question to avoid confusion with the accepted answer. – BeginnersSake Oct 23 '17 at 07:49

3 Answers3

77

You can do this, why not!? You can run the following single command to install package-x and package-y:

sudo apt-get install package-x package-y

Note:

It has been mentioned that you can add the -y flag to apt-get to answer Yes to all the prompts. This usually only saves you from having to say Yes once, anyways. It's nice to know about the -y flag, but be careful, because it can also automatically remove things that you may not want removed. Typically, I omit the -y flag and manually review all Added or Removed packages to prevent myself from making mistakes that could have horrible affects on my computer. However, apt-get upgrade -y seems to be a good option and less volatile.

sudo apt-get upgrade package-x package-y -y
pomsky
  • 67,112
  • 21
  • 233
  • 243
earthmeLon
  • 11,042
  • 1
  • 36
  • 60
  • I'll check this one too. – BeginnersSake Jan 21 '17 at 17:51
  • This works but what if I am installing package x and in middle of the installation I want to start another installation (in this case consider package y). Is it possible to do so? – BeginnersSake Jan 21 '17 at 18:03
  • 10
    This is a different question. One limitation of `apt` is that you can only have one `apt` process at a time. This is a **good thing**, as it prevents you from ruining your system. In the case that you want to install package Y, you either wait for X to finish, or you stop X and install them together. – earthmeLon Jan 21 '17 at 18:09
  • When one package does not exist (between distros) the whole command fails. How to install then a list of packages? – pbies Dec 17 '20 at 01:18
16

To install packages use:

sudo apt-get install package-name

To install multiple packages simply list one after the other:

sudo apt-get install package-name1 package-name2 package-name3

To force apt-get install to answer yes to any are you sure you want to install this package? questions which may arise add a -y to the end

sudo apt-get install package1 package2 package3 -y

I'm not sure about other users but I find it helpful to keep a file that has a list of all packages/programs that I commonly use so that in the event I need to reinstall I can simply copy and paste the command rather than having to spend the next few weeks figuring out what I have and haven't got.

As Angel identified below keeping a copy of dpkg --get-selections will allow you to keep handy all the packages you had in case of reinstall. You can also restore pkg metadata by using apt-mark showauto > auto.lst and apt-mark showmanual > manual.lst to get metadata and apt-mark auto < auto.lst and apt-mark manual.lst to restore it.

theYnot
  • 629
  • 5
  • 12
  • 1
    Also, one thing I do to save time is have a file backedup somewhere with the command to install all the programs I commonly use so that if I have to reinstall for some reason I simply copy and paste the comman and walk away for half an hour – theYnot Jan 21 '17 at 23:50
  • 1
    If you want to improve another answer, please suggest an edit to it and don’t create a new (incomplete) answer. – David Foerster Jan 22 '17 at 01:35
  • 2
    Keeping a copy of `dpkg --get-selections` will allow you to install all the packages you had in case of reinstall. – Ángel Jan 22 '17 at 03:28
  • Funnily enough @Ángel I had to reinstall my OS yesterday. I tried `dpkg --get-selections` and it worked a treat. I did some homework and came across this answer (http://askubuntu.com/questions/101931/restoring-all-data-and-dependencies-from-dpkg-set-selections) which expands upon doing this and says that to restore `pkg` metadata to use `apt-mark showauto > auto.lst` and `apt-mark showmanual > manual.lst` to get metadata and `apt-mark auto < auto.lst` and `apt-mark manual.lst` to restore it. – theYnot Jan 24 '17 at 06:18
  • Fails every single time in a docker image. – Sephethus Aug 23 '23 at 17:02
2

In Linux, apt-get/yum/etc can be compared to an "Installer" in windows. One installer can install only one software at a time. You can always install 2 or more software from source, binaries in parallel. Most Linux distributions have a common package manager, or "installer" for most software supported by that distribution. Unlike windows, in which each software comes with its own installer and hence they run in parallel.

In case you were seeking this

Cybertrons
  • 91
  • 3