If I'm not wrong there's a new command unifying apt update && apt upgrade in 18.04 or some later beta, with some argument -u or -d.

Am I correct, or there is something similar?

  • 1
    dude, that would be so cool... what is the full command? – Joshua Besneatte Sep 21 '18 at 1:14
  • I just did update/upgrade individually trying both flags. update using either flag did not auto-upgrade and upgrade using those flags did not auto update... hrm – Joshua Besneatte Sep 21 '18 at 1:20
  • Hmm, I once saw a mentioning about this in a post here but I didn't find that post... – JohnDoea Sep 21 '18 at 1:21
  • that would be so cool... I hope you figure it out! – Joshua Besneatte Sep 21 '18 at 1:24
  • 4
    You could just make a bash alias for it. – FortuneCookie101 Sep 23 '18 at 3:41

This is a pending feature request (LP#1709603), and as far as I can tell there has been no development activity on it (neither on Ubuntu nor on Debian).

There is an implemented feature that automatically runs an update when adding a PPA using add-apt-repository, though (and associated options, which have changed as this behaviour is now the default).


Set in terminal with command alias your new defined command for this like for example :

alias update='sudo apt-get update && sudo apt-get dist-upgrade'

Then you have your new command "update" and you can lean back, when typed "update" in terminal.

  • 3
    @JohnDoea - from time to time, but not always - you should do : sudo apt-get autoremove – dschinn1001 Sep 23 '18 at 21:36
  • But, you need to add this alias to $HOME/.bashrc or $HOME/.bash_aliases if it exists so that it will be defined in any new shells you open and the next time you login. – Joe Sep 27 '18 at 6:35

I doubt that that change will be included, unfortunately, but you can do something similar to the other answers-so-far, with some extra niceties.

A script at /usr/local/bin/update

This has the following nice benefits that the other answers-so-far don't have:

  • This completely avoids the problem that if sudo apt-get update takes a while, sudo apt-get upgrade might ask you for your password again, so you come back from your lunch break expecting upgraded packages and now you have to wait for a while for them to download and install.
  • This lets you know if a restart is required (like if you get a new kernel).
  • This works for all sudo users, not just you.
  • This does many more package-upgrading-related tasks than just sudo apt update && sudo apt upgrade, like upgrading the BIOS on some systems and upgrading snaps.

I posted this elsewhere a while back, so I'll include it here.

  1. Open a terminal (press Ctrl+Alt+T) and run:

    sudo touch /usr/local/bin/update
    sudo chmod 0755 /usr/local/bin/update
    sudo nano /usr/local/bin/update
  2. Paste the following into the terminal:

    if [ "$( /usr/bin/id -u )" -ne "0" ] ; then
     echo 'Please run using sudo.'
     exit 1
    set +e
    /bin/rm -f /var/cache/app-info/xmls/fwupd.xml
    /usr/bin/snap refresh
    /usr/bin/apt update
    /usr/bin/appstreamcli refresh --force
    /usr/bin/apt-file update
    /usr/bin/apt full-upgrade -y
    /usr/bin/apt autoremove --purge -y
    /usr/bin/apt clean
    /usr/bin/fwupdmgr refresh
    /usr/bin/fwupdmgr update
    /sbin/fstrim --all
  3. Read the section below about things that you might want to change. Make any changes you feel like.

  4. Press Ctrl+O to save the file. That's the letter O, not zero.
  5. Press Enter to accept the filename.
  6. Press Ctrl+X to exit nano.

Now you can run it with:

sudo update

Things that you might want to change

Feel free to customize anything in it that you don't like. You can even add new commands to it to do additional upgrade-related housekeeping tasks.

Note that this uses apt full-upgrade rather than apt upgrade, which can remove packages. It also uses apt autoremove --purge which removes packages that are supposedly no longer needed (like any kernels older than the latest two) along with their configuration files.

Note also that none of the lines requires sudo because we're running the entire script with sudo, so leave that out.

Here are what the commands do:

  • Requires running the script with sudo (the if-fi block).
  • Continues on to further commands even if there's an error in one command (set +e).
  • Deletes the firmware (e.g., BIOS) update metadata, because it's giving me AppStream errors (we download it fresh below, so this isn't as problematic as it initially appears to be).
  • Updates your snaps to their latest versions.
  • Updates the APT package information.
  • Updates the AppStream metadata.
  • Updates apt-file's metadata. apt-file list package-name is a nice way of finding out what files a package installs (alternatively, dpkg -S /path/to/file is a nice way of finding out which package a file belongs to).
  • Does an APT full-upgrade.
  • Removes newly-unnecessary packages and their configuration files.
  • Deletes any APT package files that were downloaded and left behind.
  • Updates the firmware update metadata.
  • Installs any new firmware updates.
  • Updates the locate command's (a fast way to find files outside of /home) database with the filenames that exist now after all the above updates.
  • TRIMs any SSDs. TRIM notifies the SSD itself about disk space that isn't used anymore (e.g., space that was used by deleted files). This helps it to do wear-leveling better.
  • Displays a restart needed notice if a restart is needed (e.g., after a new kernel is installed).
  • Nice. Although, last I looked, apt-file wasn't installed by default, so that would have to be installed to prevent the script from failing. Personally, I like to do things like this in separate steps so that if I notice anything unusual in one step, I can address that before potentially compounding a problem. Never noticed full-upgrade before. Did that replace dist-upgrade? I don't see the latter in man apt now. – Joe Sep 27 '18 at 6:49
  • dist-upgrade shows up in man apt-get, but not in man apt. It appears to be a bit different than full-upgrade. It seems to have more leeway for uninstalling things to allow new installs, but I don't appreciate the subtleties of it. – Joe Sep 27 '18 at 6:58

Edit your ~/.bashrc file and add this:

update () {
    sudo apt-get update
    sudo apt-get upgrade "$@"

Save the file, close any open terminal(s) and open a new terminal.

Test from the command line like this:

$ update -s
Hit:1 http://archive.canonical.com/ubuntu xenial InRelease
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease                          
Ign:3 http://dl.google.com/linux/chrome/deb stable InRelease                               
Hit:4 http://ca.archive.ubuntu.com/ubuntu xenial InRelease                                 
Hit:5 http://ppa.launchpad.net/fossfreedom/indicator-sysmonitor/ubuntu xenial InRelease    
Hit:6 http://ca.archive.ubuntu.com/ubuntu xenial-updates InRelease                         
Hit:7 http://dl.google.com/linux/chrome/deb stable Release                                 
Hit:9 http://ca.archive.ubuntu.com/ubuntu xenial-backports InRelease                       
Hit:10 http://ppa.launchpad.net/peek-developers/stable/ubuntu xenial InRelease
Hit:11 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease       
Reading package lists... Done                      
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  binutils google-chrome-stable
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Inst google-chrome-stable [69.0.3497.92-1] (69.0.3497.100-1 Google:1.0/stable [amd64])
Inst binutils [2.26.1-1ubuntu1~16.04.6] (2.26.1-1ubuntu1~16.04.7 Ubuntu:16.04/xenial-updates [amd64])
Conf google-chrome-stable (69.0.3497.100-1 Google:1.0/stable [amd64])
Conf binutils (2.26.1-1ubuntu1~16.04.7 Ubuntu:16.04/xenial-updates [amd64])

You will be prompted for your password if you haven't used the sudo command in awhile.

  • "$@" is an array ins't it? I don't understand why we need it there. – JohnDoea Sep 27 '18 at 16:42
  • @JohnDoea "$@" is used for all array elements. "$*" is used for all array elements with array separators (for example I use | as array separator instead of space because my fields (array elements) often contain spaces). In bash / shell the $@ variable also links to all the parameters passed to a function. You narrow it down with $1 for first parameter, $2 for second parameter, etc. At least I think that's the way to explain it. – WinEunuuchs2Unix Sep 28 '18 at 1:56

Another option that I use quite frequently for user-specific scripting is simply:

mkdir bin
cd bin
nano up

Basically you're making a bin folder that bash looks for in every user and refreshes when you reboot. All you need for a simple update script like you're talking about, is this:

echo "System Upgrade Commencing!"
sudo apt update
sudo apt upgrade
echo "System Upgrade Complete!"



And voila. Simple script for updates and upgrades. Personally I add a lot more to my scripts for automation, such as "sudo apt upgrade -y", uptime, date and other tools for post-upgrade "sudo apt autoremove", "sudo apt autoclean" etc. You can also add some complexity by checking for packages that have been improperly installed if you want to query DPKG for possible errors, check your hard disk for faults, or list out the current processes running on your machine. Scripting is a free land of adventure and joy, good luck and have fun.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.