20

I know that there are three command to update and then upgrade the whole system, these are:

  • sudo apt-get update # Fetches the list of available updates
  • sudo apt-get upgrade # Strictly upgrades the current packages
  • sudo apt-get dist-upgrade # Installs updates (new ones)

Is there a super-upgrade command that combines all these commands to one?

  • 1
    No, you can do at most sudo apt-get update && sudo apt-get dist-upgrade – heemayl Feb 14 '16 at 8:46
  • 1
    It's still one command-line! ;-) – Fabby Aug 30 '18 at 18:33
  • For those who shall stumble upon this question someday, here's a related one to run update and upgrade as one-liners askubuntu.com/a/1086022/295286 – Sergiy Kolodyazhnyy Oct 22 '18 at 8:28
27

There are 3 decent choices:

  1. You could create a script something like the following:

    #!/bin/bash
    set -e
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    

    Call it something like update.sh and place it in /usr/local/bin and then make the script executable by running:

    sudo chmod +x /usr/local/bin/update.sh
    
  2. Another method would be to create a bash alias (in ~/.bashrc) or wherever you normally store your aliases:

    alias update='sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade'
    
  3. A final method would be to simply string the 3 commands together on the commandline:

    sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
    

A few choices...

Reference:

| improve this answer | |
  • 7
    When you are using dist-upgrade there is no point in doing upgrade beforehand.. – heemayl Feb 14 '16 at 9:03
  • 3
    @heemayl: In theory yes. In practice there are corner cases where a direct dist-upgrade may fail but upgrade followed by dist-upgrade will not. This is largely due package dependency definition bugs or mixing packages from different releases/distributions/PPAs. If one only uses packages from Canonical's official repositories for exactly one release (the default), such errors should be extremely rare and fixed quickly. – David Foerster Sep 21 '16 at 17:50
  • 2
    There's also the impress-friends variant of #3: for x in update {,dist-}upgrade; do sudo apt $x; done – Eli Barzilay Jun 7 '18 at 23:30
  • 1
    In step 1, what does "set -e" do? – karjedavpalaa Dec 19 '18 at 3:43
9

We can have a one-liner command (no need to scripts, just copy-paste)

sudo apt update -y && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt clean -y && sudo apt autoclean -y
  • update - updates the list of packages but do not install
  • upgrade - install new versions of packages if new versions are available
  • full-upgrade - performs the function of upgrade but will remove currently installed packages if this is needed to upgrade the system as a whole (fixing bad dependencies then)
  • autoremove, autoclean and clean - clean old packages which are not needed any more
  • option -y does not request for permission on every step
| improve this answer | |
7

If you are annoyed by too much typing, you can define yourself an "alias". This can be done e.g. by adding a line to the end of your $HOME/.profile like this:

alias sau='sudo aptitude update && sudo aptitude upgrade'

(of course you can replace "sau" by something else -- for me that's an acronym to Sudo Apt-get Update). After saving the file, open a new shell (or "source" the .profile again running . $HOME/.profile. Now you can always simply type "sau" to do the complete job. Works great for me with multiple machines.

| improve this answer | |
  • Hm. I guess I was just asking someone to tell me to alias it :P – polandeer Jul 10 '12 at 0:09
  • Yeah, but that's the only way to do it with a "single command". And your question did not exclude this ;) – Izzy Jul 10 '12 at 8:13
  • Tricky. Anyways, the only reason I asked was because I wanted to understand apt better, not because I'm too lazy to write sudo aptitude update && sudo aptitude upgrade The reason I asked was because you can do it with pacman (sudo pacman -Syu --noconfirm). – polandeer Jul 12 '12 at 12:14
  • If you have to do that often and on multiple machines, you're glad you can at least have an alias. However: apt-get update has a parameter -u, according to the man page that shows available updates. Did not try whether it then asks to apply them (have no Ubuntu/Debian near me to check right now). – Izzy Jul 12 '12 at 13:31
3

Unfortunately, the two commands have to be executed separately.

| improve this answer | |
2
sudo apt install unattended-upgrades

This is the best line yet. All of the other solutions you have to type the one line over and over again every day. This is truly the one-command solution. See offical apt documentation from ubuntu!

By editing the .conf files of this package in /etc you can set the frequency of update, install, clean, autoremove...

Or simply and email including A notification that an update is available with the list of package names

A nice little log file is generated with each change, and I imagine a little script could be written as a gui extension to pop up in the desktop notifications too (off topic haha)

| improve this answer | |
2

Is there a super-upgrade command that combines all these commands to one?

Well.. bad news is that no, there isn't. Good news though is that here I've put together one.

And to go on with the idea of simplification I've turned its creation into a "single" command line. So here it is:

echo "sudo apt update && sudo apt -y upgrade && sudo apt -y dist-upgrade && sudo apt -y autoremove && sudo apt autoclean" > update && sudo mv update /usr/local/bin/update && sudo chmod +x /usr/local/bin/update

Now, whenever the need for updating arises you just type update in the terminal, input your password and voilà.


This might look like one of those incomprehensible things you only copy-paste from. But it doesn't really have to be ! See it's actually quite simple, so..

What this is :

  1. Every update command (and then further commands) were concatenated using && (including apt autoremove to remove no longer used dependencies).
  2. -y was added to every apt command that would otherwise prompt for a positive answer to perform its actions.
  3. echo was placed in front of the command and the line was surrounded with "" so its characters wouldn't escape.
  4. > was used to redirect/write echo's output (our line) to an "update" file.
  5. The file is moved to /usr/local/bin/ so it is executable from anywhere. Writing on this path requires superuser access which is why it's not possible to do it in the step before.
  6. The file was turned into an executable using chmod.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy