60

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?

13
  • 1
    haven't you noticed any tutorial that has apt-get install p1 p2 p3?
    – Aloha
    Commented Jan 22, 2017 at 10:37
  • 1
    Possible duplicate of How to make a package manager wait if another instance of APT is running?
    – mniess
    Commented Oct 20, 2017 at 11:56
  • @mniess: see above Commented Oct 21, 2017 at 7:09
  • 1
    @mniess: And the comment on the comment clearly explains why that is a different question from the wording of the original question. Commented Oct 22, 2017 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. Commented Oct 23, 2017 at 7:49

3 Answers 3

83

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
3
  • 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? Commented Jan 21, 2017 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
    Commented Jan 21, 2017 at 18:09
  • When one package does not exist (between distros) the whole command fails. How to install then a list of packages?
    – pbies
    Commented Dec 17, 2020 at 1: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.

5
  • 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
    Commented Jan 21, 2017 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. Commented Jan 22, 2017 at 1:35
  • 2
    Keeping a copy of dpkg --get-selections will allow you to install all the packages you had in case of reinstall.
    – Ángel
    Commented Jan 22, 2017 at 3: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 (askubuntu.com/questions/101931/…) 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
    Commented Jan 24, 2017 at 6:18
  • Fails every single time in a docker image.
    – Sephethus
    Commented Aug 23, 2023 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

1
  • yep the OG was prolly looking for this answer Commented Jun 15, 2022 at 18:07

You must log in to answer this question.

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