23

I was looking for some package (nautilus-terminal), and accidentally did this:

$ sudo apt-get install nautilus-
Reading package lists... Done                                                                                                                                                                                                 
Building dependency tree                                                                                                                                                                                                      
Reading state information... Done                                                                                                                                                                                             
The following packages were automatically installed and are no longer required:                                                                                                                                               
  apturl apturl-common libgail-3-0 linux-headers-4.4.0-57 linux-headers-4.4.0-57-generic linux-image-4.4.0-57-generic linux-image-extra-4.4.0-57-generic                                                                      
Use 'sudo apt autoremove' to remove them.                                                                                                                                                                                     
The following packages will be REMOVED:                                                                                                                                                                                       
  gnome-session-flashback nautilus nautilus-sendto nautilus-share ubuntu-desktop                                                                                                                                              
0 upgraded, 0 newly installed, 5 to remove and 69 not upgraded.                                                                                                                                                               
After this operation, 2 031 kB disk space will be freed.                                                                                                                                                                      
Do you want to continue? [Y/n] ^[[^C                                                                                                                                                                                          

That's quite dangerous because remove is much harder to mistype than a simple dash from a failed autocompletion.

Is that an equivalent of apt-get remove? I couldn't find any documentation for that. Edit: except for overlooking the man page...

pomsky
  • 68,507

2 Answers2

29

From man apt-get:

install
   install is followed by one or more packages desired for
   installation or upgrading. Each package is a package name, not a
   fully qualified filename (for instance, in a Debian system,
   apt-utils would be the argument provided, not
   apt-utils_1.2.10_amd64.deb). All packages required by the
   package(s) specified for installation will also be retrieved and
   installed. The /etc/apt/sources.list file is used to locate the
   desired packages. 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.
muru
  • 197,895
  • 55
  • 485
  • 740
  • Hence OP should be doing: sudo apt install nautilus && sudo apt install nautilus-terminal where OP had gone through with the remove command else: sudo apt install nautilus-terminal if NO was chosen? – George Udosen Feb 06 '17 at 05:00
  • 3
    The rationale for this feature is that sometimes you want to install a package that conflicts with one that is already installed, but one of them is required by some other package, so both actions need to be in the same run. E.g. apt install sysvinit-core systemd-sysv- (either is required by the Essential init package) or apt install msmtp postfix- (lots of packages depend on an MTA). – Simon Richter Feb 06 '17 at 10:59
  • 1
    @SimonRichter trying apt -s install upstart-sysv on 16.04 indicates apt will automatically remove systemd-sysv (since they conflict). Ditto for msmtp-mta and postifx. A more complicated example might be needed, where apt might pick the wrong package to remove. – muru Feb 06 '17 at 11:04
  • Thanks for fixing my blind eye. Noted that apt-get remove foo+ installs foo. – Ondra Žižka Feb 06 '17 at 18:56
  • That's kind of a neat feature. :D – Andrea Lazzarotto Feb 06 '17 at 19:05
1

The following two mean the same:

# apt-get remove nautilus
# apt-get install nautilus-

So if you are merely installing or removing one thing, then there is really no reason to choose one over the other, and the remove command may as well be used.

Where the "minus" operator comes in handy is in cases where you want to remove one package and install another in the same operation:

# apt-get install php5-cgi libapache2-mod-php5- 

I couldn't think of a better example, but there are some situations where removing one and adding another in separate operations could trigger additional unnecessary installations or removals, while doing them both in a single operation will immediately satisfy some co-dependencies and make it an overall simpler operation.

As for whether adding the minus makes it easier to accidentally remove something unintentionally, I first and foremost refer you to how easy it is to create damage to your system unintentionally on the command line anyway. It was not built to protect you from yourself and there are billions of even simpler commands that can hose your system. But secondly, in this case it tells you exactly what it's going to do and confirms that you really want to do it. This is low risk.

thomasrutter
  • 36,774