In order avoid typing out all of the apt-get commands when updating my computer I have made a simple alias command to do it. But I really want to be able to just type in my alias and let it do its thing and not have to wait to for the yes/no prompt to type in "y". Is there a simple way to bypass this prompt or maybe add "yes" in the alias somewhere?
6 Answers
Sure, although I have never tried it as an alias but it should work:
sudo apt-get update && sudo apt-get -y upgrade
-
I will edit and remove the -y from update if it bothers you One Zero. :)– wojoxApr 2, 2012 at 16:04
-
-
1
-
6For grub override conf question you have to set this in front of it
sudo DEBIAN_FRONTEND=noninteractive apt-get...
Dec 14, 2018 at 11:33 -
@saitam - thanks.... the DEBIAN_FRONTEND variable is exactly what I was looking for! Kodos. Jul 7, 2019 at 18:40
apt-get -o Dpkg::Options::='--force-confold' --force-yes -fuy dist-upgrade
To clarify Dpkg::Options::='--force-confold'
from the man-page:
--force-confold
: do not modify the current configuration file, the new version is installed with a.dpkg-dist
suffix. With this option alone, even configuration files that you have not modified are left untouched. You need to combine it with--force-confdef
to let dpkg overwrite configuration files that you have not modified.
-
16Could you be more specific? What does this command do and how does it work?– SethDec 10, 2013 at 6:09
-
Nice to see the deeper answer to this question, thanks Vadim. Nov 20, 2017 at 17:17
apt-get update && apt-get upgrade -y && apt-get autoremove && apt-get autoclean
This updates the packages, upgrades the packages, removes unused packages, then removes old versions of packages.
You can copy paste that into:
nano -w yourscript.sh
then
chmod 777 yourscript.sh
then
./yourscript.sh
So long as you use su
before all those steps, which I always do.
-
7This answer goes... too far. He might not want to delete old/unused packages. Also I don't think you should ever use chmod 777 if it can be avoided. And I believe in Ubuntu the recommended way is to use apt-get rather than apt. Apr 1, 2015 at 6:32
-
1
-
2@AndreasHartmann Agreed. That script is a security risk if put on 777. Use chmod u+x instead (only sets the executable bit for the file owner)– 520Oct 16, 2019 at 13:48
-
First, you can also put
sudo
in front of each command and second, you can write a script that automatically generatesyourscript.sh
which I could provide if there is interest for that.– CadoizFeb 10, 2023 at 11:28
You could also do it quietly and then get a notification when it's all done. The downside to this is you will only see errors reported and will not see what is updated.
sudo apt-get update -qq && sudo apt-get dist-upgrade -qq && echo "All up to date now!" && notify-send "All up to date now!"
@wojox answer is correct, but you can take the alias even further for more functionality. I have been using this for quite some time now without issue. This will perform the upgrades (confirming with -y
) and then testing to see if a reboot is required. If a reboot is required, you can do so by pressing [ENTER]
, or cancel and reboot later by pressing [CTRL+C]
. If no reboot is required, the alias finishes letting you know so.
My alias is sur
for sudo upgrade reboot
, but feel free to name it what you choose. Add the following to your .bashrc
file:
alias sur='sudo apt update && sudo apt upgrade -y && if sudo test -f /var/run/reboot-required; then read -p "A reboot is required to finish installing updates. Press [ENTER] to reboot now, or [CTRL+C] to cancel and reboot later." && sudo reboot; else echo "A reboot is not required. Exiting..."; fi'
You can continue to chain more commands if you would like to do more with the same alias. Here is the complete alias from my .bashrc
that will also remove unused packages:
alias sur='sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && if sudo test -f /var/run/reboot-required; then read -p "A reboot is required to finish installing updates. Press [ENTER] to reboot now, or [CTRL+C] to cancel and reboot later." && sudo reboot; else echo "A reboot is not required. Exiting..."; fi'
I actually stumbled across this thread while checking to see if there is an option to skip the prompt for configuration file overwrites, which was provided in @Vadim's answer above! My new alias is this:
alias sur='sudo apt update && sudo apt -o Dpkg::Options::="--force-confdef" dist-upgrade -y && sudo apt autoremove -y && if sudo test -f /var/run/reboot-required; then read -p "A reboot is required to finish installing updates. Press [ENTER] to reboot now, or [CTRL+C] to cancel and reboot later." && sudo reboot; else echo "A reboot is not required. Exiting..."; fi'
I then push this new .bashrc
file to each of my managed servers simply with:
while read HOST; do scp .bashrc username@$HOST:/home/username; done < managedhosts.txt
Defining a function has been the most straightforward, universal method I've found.
I've personally never gotten the update && -y upgrade
to work correctly. Some distros have a problem with a single command (or alias) using the &&
operator and -y
argument together.
function update ()
{
sudo apt update
sudo apt -y upgrade
}