How to install updates via command line?
Solution 1:
Use this:
sudo apt update # Fetches the list of available updates
sudo apt upgrade # Installs some updates; does not remove packages
sudo apt full-upgrade # Installs updates; may also remove some packages, if needed
sudo apt autoremove # Removes any old packages that are no longer needed
Documentation about each apt
option can be found in the the manpages for apt. These are also available by running man apt
in your terminal.
Use of both upgrade
and full-upgrade
together is usually not needed, but it may help in some cases: see Debian documentation about Upgrades from Debian 9.
Solution 2:
Execute all the commands by typing sudo
once:
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
or:
sudo -s -- <<EOF
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get autoremove -y
apt-get autoclean -y
EOF
or even shorter in a for loop (thanks @dessert!):
sudo bash -c 'for i in update {,dist-}upgrade auto{remove,clean}; do apt-get $i -y; done'
See the package management with APT maintenance commands documentation for more details.
Solution 3:
This is normal behavior.
The message you see on login has been appended to the server status 'Message-Of-The-Day', which is only updated each calendar day (or on server boot / startup). Have a look at the contents, using
cat /etc/motd
Still seeing the same updates available, after running
sudo apt-get update && sudo apt-get upgrade
is to be expected. If you then re-run this command you will only be prompted for any further updates if even further (newer) updates have been released.
Solution 4:
Once your log into your server, run the command below.
sudo apt-get upgrade
It should do the trick. Maybe you just need to restart your server.
Solution 5:
In my case, I had an incorrect or not accessible URL in /etc/apt/sources.list. After removing this URL, I was able to update all packages successfully.
Commands:
sudo vi /etc/apt/sources.list
sudo apt-get update && sudo apt-get upgrade