0

this is my first question on this website so bear with me. I've use Linux for a decent amount of time and want to create a shell update to automate the process of update, with out using GUI since its slow and inefficient. I chained a few commands together so I don't have to do it individually, here is the command.

sudo apt update && sudo apt upgrade && sudo apt autoremove && sudo apt autoclean

My friend also uses Linux and says the autoremove command might mess with stability of the entire operating system, but I value security more. The question I'm asking is if this script is okay, or should I do it differently, maybe with out autoremove or structure it completely different. Sorry if this question doesn't make any sense, thanks in advance.

pLumo
  • 26,947
C Snap
  • 1
  • I removed Linux Mint, as it has nothing to do with the question and would make it off-topic on this site. Please know, that askubuntu is Ubuntu only, no derivates. Next time, you may want to ask in Unix&Linux Stackexchange. – pLumo Mar 22 '21 at 07:02
  • If you want to clear out even more packages from cache, consider clean instead of autoclean (see here). – Artur Meinild Mar 22 '21 at 07:30
  • Similar question & discussion. https://ubuntuforums.org/showthread.php?t=2459453 – oldfred Mar 22 '21 at 14:12

2 Answers2

0

The command looks fine with me. About what your friend said, I can't see why "autoremove" would mess with the stability of the system. According to the man pages:

autoremove is used to remove packages that were automatically
installed to satisfy dependencies for other packages and are now no
longer needed as dependencies changed or the package(s) needing
them were removed in the meantime.

So, if the system has become unstable, it's basically saying that apt has made a mistake in determining if a package is unnecessary...

Depending on what you want to achieve, you might want to replace upgrade with full-upgrade. (See the man pages of apt for an explanation.)

As an alternative, you might consider doing upgrades automatically. Perhaps you can take a look at this.

But going back to your original question, the command that you have written looks fine to me.

Ray
  • 2,071
0

To automate properly, you should:

  • use -y for upgrade and autoremove

    -y, --yes, --assume-yes Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactively. (via man apt-get)

  • use sudo once for all commands instead of running it for each command to avoid password entry when your command run time exceeds the sudo timeout.

sudo bash -c 'apt update && apt upgrade -y && apt autoremove -y && apt autoclean'

autoremove should be safe to run, but you might want to know what it does, to avoid getting issues: It removes all packages that no other package depends on, if you have not explicitly installed it. That can make trouble if you accidentally removed a meta-package (= a package that does not contain any software, but depends on other packages. E.g. ubuntu-desktop). For more information, please see here.


However, instead of running your own script, you could simply use unattended-upgrades for this. See here.

pLumo
  • 26,947
  • Thanks for your help, I'm just going to have to understand why its structured that way so I can have a better understanding how all these commands work. I've used Linux for 2 years, but I've only been learning the cli for around 7 months. – C Snap Mar 23 '21 at 07:35