8

When I install Ubuntu, the first thing I usually do is remove some programs and install some others. To get that done, I enter the following in a terminal:

sudo apt-get remove applicationA applicationB applicationC && sudo apt-get install applicationX applicationY applicationZ.

This works nicely, but the problem is that I have to confirm twice: first I have to confirm the removal of the applications, and after some time I have to confirm the installation of the others. It would be great if I only had to confirm once, because I wouldn't have to come back to the computer in the meantime. Is there any command to get that done?

Please note that I'm not looking for workarounds in e.g. Synaptic Package Manager. I want to do this from the command line.

Thanks.

2
  • Use Synaptic, search, install tick "close window when installation finishes" and done Jan 29, 2012 at 11:01
  • 1
    That's not what I mean. I want to use the command-line-interface, not Synaptic. Jan 29, 2012 at 11:04

4 Answers 4

17

As an alternative to the answers already posted, you can also select to install and remove packages in one command with aptitude. With aptitude install commands add - after the package name to have it removed, and with aptitude remove commands add + after the package name to have it installed.

If you enter

sudo aptitude install pkg1 pkg2-

the first packages will be installed while the second one will be removed.

However, on the other hand, if you use

sudo aptitude remove pkg1+ pkg2

the second package will be removed and the first installed.

Source: for a more detailed explanation of apt and aptitude, see the Debian Handbook.

2
  • Wow, that worked so much better than messing around with apt-get. I was trying to downgrade my gcc packages from 4.9 to 4.7, but that appears to be impossible with apt-get because removing gcc would remove apt itself (!) and downgrading is either impossible or very difficult with apt-get. But when I copied the exact command I'd been using with apt-get and replaced apt-get with aptitude, it recognized what I was trying to do, explained the problem (!), and suggested a fix (!!). May 1, 2018 at 21:43
  • 2
    Dunno of 2012, but these days apt-get also has this ability, see the answer by Benedikt Köppel.
    – Ruslan
    Oct 13, 2019 at 9:29
16

From the apt-get man page:

install [...] If a hyphen is appended to the package name (with no intervening space), the identified package will be removed if it is installed. Similarly a plus sign can be used to designate a package to install. These latter features may be used to override decisions made by apt-get's conflict resolution system.

You can append a hyphen to the package name, then apt-get will remove that package. So in order to remove package a and install b:

sudo apt-get install a- b
8

Use the -y option for apt-get.

From the man page:

-y, --yes, --assume-yes
      Automatic yes to prompts; assume "yes" as answer to all prompts and
      run non-interactively. If an undesirable situation, such as
      changing a held package, trying to install a unauthenticated
      package or removing an essential package occurs then apt-get will
      abort. Configuration Item: APT::Get::Assume-Yes.

So for you it would look something like sudo apt-get remove -y foo1 foo2 foo3 and sudo apt-get install -y foo foo1 foo2 foo3.

4
  • OK, so in my case, the command would be: sudo apt-get remove -y applicationA applicationB applicationC && sudo apt-get install -y applicationX applicationY applicationZ? Jan 29, 2012 at 11:09
  • Would it be apt-get remove -y or apt-get -y remove?
    – user25656
    Jan 29, 2012 at 11:52
  • It does not matter I think. Jan 29, 2012 at 12:17
  • does not matter vasa1
    – Rinzwind
    Jan 29, 2012 at 14:00
0

maybe perform both commands using only one call to sudo:

sudo sh -c 'apt-get remove a b c && apt-get install d e f'
1
  • @ScottSeverance Oh, pardon my ignorance, was too fast judging. Thx for the heads up ;) Jan 30, 2012 at 0:34

You must log in to answer this question.

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