74

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

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

Pablo Bianchi
  • 17,371

10 Answers10

70

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:

dessert
  • 40,956
andrew.46
  • 39,359
52

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
  • && states that it just runs the next command if the previous was successfully executed

Alias

You can also create an alias. Add the following line to your ~/.bashrc or ~/.bash_aliases (if you have it)

alias upev='sudo apt update -y && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt clean -y && sudo apt autoclean -y'

Run source ~/.bashrc or source ~/.bash_aliases accordingly to fetch your new alias, and now simply run

upev 

note: I chose upev for UPgrade EVerything, but you may chose anything you want.

11

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.

Izzy
  • 3,620
8
sudo apt install unattended-upgrades

This is the best line yet. All the other solutions, you have to type the one line over and over again every day. This is truly the one-command solution. See official 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).

Pablo Bianchi
  • 17,371
not-a-coderp
  • 101
  • 1
  • 4
4

Unfortunately, the two commands have to be executed separately.

3

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.
2

Just copy-paste the following alias command and execute it:

alias fup='sudo apt-get -y update;sudo apt-get -y full-upgrade;sudo apt-get -y autoremove; sudo apt-get -y autoclean'

Now, running fup will automatically do all the jobs defined in the alias.

If you need to use this frequently, do the following.

  1. Create a file named .bash_aliases in your $HOME directory. You can do that form the terminal with the following command:

    touch ./.bash_aliases
    
  2. In the .bash_aliases file paste the alias command mentioned above.

  3. Now save the file and exit.

  4. Edit your .bashrc file to export your .bash_aliases file. So run:

    gedit .bashrc
    

    and paste the following code at the end of file:

    if [ -f /home/abhyam/.bash_aliases ];then
    source /home/abhyam/.bash_aliases
    fi
    
  5. Save the file and exit.

  6. Run:

    source .bashrc
    
  7. Now you can run the command fup to fully update and upgrade your system anytime.

The benefit of creating the .bash_aliases file is that you can also create custom aliases in that file for other actions and that it will automatically get sourced each time you open a terminal.

0

I found this thread looking for the same treasure. In case anyone is still interested, I've been working on a git project which runs through the same commands.

#!/usr/bin/bash
    RED='\033[0;31m'
    GREEN='\033[0;32m'
    PURPLE='\033[0;35m'
    NC='\033[0m' # No Color

#Region --- Updates echo -e "${PURPLE}RUNNING: sudo apt update --fix-missing${NC}"

for i in {1..100} do
sudo apt clean sudo apt update --fix-missing status=$? if test $status -eq 0 then echo -e "${GREEN}SUCCESS: sudo apt update --fix-missing${NC}\n" break else echo -e "${RED}FAILED: sudo apt update --fix-missing${NC}\n" sleep 1m fi done

#Region --- Upgrades for i in {1..100} do
echo -e "${PURPLE}RUNNING: sudo apt upgrade -y${NC}" sudo apt full-upgrade -y status=$? if test $status -eq 0 then echo -e "${GREEN}SUCCESS: sudo apt upgrade -y${NC}\n" break else echo -e "${RED}FAILED: sudo apt upgrade -y${NC}\n" sleep 1m fi done

#Region for i in {1..100} do
echo -e "${PURPLE}RUNNING: sudo apt autoremove -y${NC}" sudo apt autoremove -y status=$? if test $status -eq 0 then echo -e "${GREEN}SUCCESS: sudo apt autoremove -y${NC}\n" break else echo -e "${RED}FAILED: sudo apt autoremove -y${NC}\n" sleep 1m fi done

#Region --- Exiting BasherUpdate echo -e "${PURPLE}Exiting BasherUpdate...${NC}\n" exit 0

Note that I used a loop on the apt update command because I was getting mirror sync in progress errors and wanted it to keep trying. Hope this helps and let me know if you have suggestions!

Hasted
  • 1
0

Found this elsewhere:

    sudo -- sh -c "apt update && apt upgrade -y"

Can also alias this to use 'upgrade' in your ~/.bash_aliases with something like:

    alias upgrade="sudo -- sh -c 'apt update && apt upgrade -y'"

and do a 'source ~/.bash_aliases' to make it work

0

I usually like to have a file like clean.sh and run it when I want to upgrade, update and clean everything.

#!/bin/bash

run_command() { echo " > $1" eval "$1" }

apt clean

run_command "sudo apt-get update" run_command "sudo apt-get upgrade -y" run_command "sudo apt-get dist-upgrade -y" run_command "sudo apt-get clean" run_command "sudo apt-get autoclean" run_command "sudo apt-get autoremove -y" run_command "sudo apt-get purge -y" run_command "sudo apt-get autoremove --purge -y"

bun (remove if you don't have bun installed)

run_command "bun upgrade"

orphaned packages

run_command "sudo apt-get autoremove --purge -y"

logs

run_command "sudo journalctl --vacuum-time=3d"

snap

run_command "sudo snap refresh" run_command "sudo snap remove --purge $(snap list --all | awk '/^disabled/{print $1}')"

apt cache

run_command "sudo rm -rf /var/lib/apt/lists/*"

flatpak

run_command "flatpak update -y" run_command "flatpak uninstall --unused"

npm cache

run_command "npm cache clean --force"

old kernels

run_command "sudo apt-get autoremove --purge -y"

echo "Clean completed"

sudo ./clean.sh
kos
  • 41,268
tiago
  • 101