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 full-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 full-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 {,full-,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
Related videos on Youtube
Lakshmi
Updated on September 18, 2022Comments
-
Lakshmi over 1 year
When I log into my web server via SSH I see the information:
88 packages can be updated. 80 updates are security updates
I tried
apt-get update
thenapt-get upgrade
but each time I log in I still see the message about updates. How do I install them? -
Lakshmi over 11 yearsThank you for your answer but I did try sudo apt-get upgrade. Restarting the server is out of the question because I have sites on it.
-
Evandro Silva over 11 yearsif you installed an update that directly affects the kernel or it's a driver update or it's a critical security update, you need to restart the server.
-
NorTicUs over 11 yearsMaybe you should consider an error 503 for a minute. Do you know what kind of update this is ?
-
mcont over 9 yearsHow can you give a 503 if the server is offline?
-
hellboy about 9 yearsShould I always restart with
sudo reboot
after it? -
3lomahmed over 8 yearsI'm noticing that any file changes in the whole system doesn't show until the next calendar day, is there a way for like "refresh" to start seeing changes right away?
-
david6 over 8 yearsDo you mean updates for the content of Message-Of-The-Day, or not getting what you want after running
sudo apt-get update && sudo apt-get upgrade
? -
Bogdan Calmac almost 8 yearsThis is no longer true on 16.04. After "apt-get dist-upgrade" and a reboot I see "0 packages can be upgraded".
-
david6 almost 8 yearsThe '.. or on server reboot ..' statement above does cover that.
-
xApple over 7 yearscat: /etc/motd: No such file or directory
-
david6 over 7 yearsThis behaviour has clearly been changes, but needs more research ..
-
T04435 about 6 yearsI needed to add -y for it to work. Ubuntu 17.10
-
Jonathan Hartley over 5 yearsThe last sentence of this answer makes no sense to me. "...you will only be prompted for any further updates, even if further (newer) updates have been released." Should it perhaps read something like "...you will not be prompted for any further updates, unless even newer ones have been released since you last ran the command."
-
Tigerware over 5 yearsCurrently this gets updated without restarting.
-
jarno almost 5 yearsYou can combine
dist-upgrade
andautoremove
byapt-get dist-upgrade --auto-remove
. -
jarno almost 5 yearsThere is no need to run both
upgrade
anddist-upgrade
. -
Eliah Kagan almost 5 years@jarno
dist-upgrade
can remove packages. Usingupgrade
first may avoid this, such as when new package versions satisfy dependencies more easily than old ones. I don't know how often this helps when upgrading packages within a stable release of Ubuntu, but it's recommended in some other contexts. Personally, I rarely usedist-upgrade
in Ubuntu, and when I do, I never pass-y
. But if one is to rundist-upgrade
and pass-y
, I think it's reasonable to perform theupgrade
action first. -
Videonauth almost 5 years@jarno while you can chain
--autoremove
together with the upgrade command of your choice, it is not advisable as it can end you up with an unclean state when one of the packages fails. A better was is to use theautoremove
alone on a separate line after the update process is done, if you want to clean out the old config files too you can chain this with--purge
. -
jarno almost 5 years@Videonauth oh, it depends how
apt
is implemented. I think it should be implemented so that it does not leave system in unclean state. -
TheKarateKid almost 4 years@hellboy No need to every time. It will usually inform you if a reboot is required.
-
kas almost 4 yearsJust pointing out that
apt full-upgrade
performs the same function asapt-get dist-upgrade
, if, like me, you're comparing the commands with other answers in this question. -
Kellen Stuart over 2 years@hellboy It will tell you if a reboot is required. Also it's unclear whether you're asking if rebooting command line is required - the answer is No. It doesn't matter how you restart the machine.