Currently, to get things up to date on my Raspberry Pi, I have to type in sudo apt-get update
and sudo apt-get upgrade
. Is there a way to set it up to automatically do this? I am running Raspbian Jessie.

- 846
- 1
- 7
- 13
4 Answers
Instead of a manual cron, you can install unattended-upgrades
, which is useful to ensure the latest kernels are installed. It's mostly designed for security.
apt-get install unattended-upgrades
There are some bits that can be adjusted/configured, but the default is fine.

- 846
- 1
- 7
- 13

- 1,372
- 1
- 11
- 17
In its default configuration, unattended-upgrades
is broken in Raspbian Buster. It won't install crucial updates for the kernel and other software. Your options are:
Recommended Option:
- Install and fix unattended-upgrades:
sudo apt install unattended-upgrades
echo 'Unattended-Upgrade::Origins-Pattern {
// Fix missing Rasbian sources.
"origin=Debian,codename=${distro_codename},label=Debian";
"origin=Debian,codename=${distro_codename},label=Debian-Security";
"origin=Raspbian,codename=${distro_codename},label=Raspbian";
"origin=Raspberry Pi Foundation,codename=${distro_codename},label=Raspberry Pi Foundation";
};' | sudo tee /etc/apt/apt.conf.d/51unattended-upgrades-raspbian
For faster security updates (but less stability, as the packages haven't been approved for rasbian), you can add debian-security packages to apt:
echo 'deb http://deb.debian.org/debian-security/ buster/updates main contrib non-free' | sudo tee /etc/apt/sources.list.d/debian-security.list
You will probably need to install new apt keys for the debian repository.
Other Options:
- Work around it with by using cron-apt:
sudo apt install cron-apt
It's recommended to use unattended-updates and fix the package, because it's best suited for the purpose. Cron-apt is your second-best option, because it's also designed for a similar purpose. I'm not sure cron-apt can automatically reboot your system after a kernel update. Unattended-upgrades has that option, and in my experience reboot after kernel upgrade works with the fix above.

- 566
- 4
- 5
-
1For future reference: the correct values to use for
Unattended-Upgrade::Origins-Pattern
's keywords (e.g.origin
,label
, etc.) can be found in the output ofapt-cache policy
. – Flux Nov 16 '21 at 14:53 -
Final step to enable unattended-upgrades so it automatically runs on your system, type:
– HackSlash Jan 24 '24 at 21:52sudo dpkg-reconfigure --priority=low unattended-upgrades
Tasks can be automated using the cron utility.
To setup cron to update apt, in a terminal type:
sudo su
to access a root-level prompt. Then, run:
crontab -e
to begin editing your crontab, a table of tasks to run automatically at a given time. It will open in your preferred text editor. Modify it to include the following line:
0 7 * * 1 apt update && apt upgrade -y
This will tell the system to automatically update and upgrade your apps at 7AM every Monday. After saving and exiting, it is now activated, no further actions. Read-up on crontab to see how to adjust to your liking.
Note time trigger "0 7 * * 1" translates to 0 hours past 7 every day of every month that is a Monday. To help with changing the trigger, you can use https://cron.help.

- 4,552
- 18
- 29
-
4it's probably better to put the commands on the same line with
&&
since they are related and there's no reason to do 'upgrade' if 'update' fails. – 300D7309EF17 Dec 05 '15 at 02:36 -
in crontab
0
means Sunday but in your code you have put1
so the command would be run on Monday, not Sunday – rav_kr Dec 05 '15 at 21:14 -
7
dist-upgrade
is better thanupgrade
, you will end up with broken dependencies using onlyupgrade
. You also won't get around updates that require dialog confirmations. @tedder42 pointed out the method preferred by Debian (usingunattended-upgrades
). – ryanpcmcquen Jan 31 '16 at 18:51 -
1You missed the second sudo after adding the &&. Although it's in root crontab anyway. – user643011 Apr 12 '18 at 11:41
-
3There should not be any
sudo
in there; you've switched to theroot
account by usingsu
. The superuser's crontab is run with superuser privileges. – goldilocks Apr 12 '18 at 12:34 -
@ryanpcmcquen there is no
dist-upgrade
with apt. It's calledfull-upgrade
. I agree using it. – Ingo Oct 24 '18 at 17:27 -
1@Ingo,
full-upgrade
is justapt
's shortcut toapt-get dist-upgrade
. – ryanpcmcquen Oct 25 '18 at 14:55
You can install and configure cron-apt. Install it by doing the following:
apt-get install cron-apt
the main configuration file is /etc/cron-apt/config
One thing I add to my configuration is:
MAILON="always"
this will send an email every time it runs, not only if it encounters an error.
Note that the default setup will not automatically install the updates (there are some good reasons to not do this), but you can config it to do so. One advantage this program provides over a simple cron solution is that it gives you control over what gets installed (only download new packages, install security updates or install all updates).
To set the time it runs edit the /etc/cron.d/cron-apt file.
You can find more info and config options here
The package includes very good documentation, however it is gzipped. To extract the file:
- create a directory to work in - mkdir cron-apt_documentation
- change to the new directory - cd cron-apt_documentation
- copy the compressed file - cp /usr/share/doc/cron-apt/README.gz . (note the trailing dot)
- uncompress the file - gunzip README.gz
- read the file - cat README | less

- 34,687
- 17
- 103
- 109
/var/log/unattended-upgrades/unattended-upgrades.log
file reportedAllowed origins are: []
so basically it wasn't pulling any updates in. After updating/etc/apt/apt.conf.d/50unattended-upgrades
to include"origin=Raspbian,codename=${distro_codename},label=Raspbian";
updates started to come in. – Rabarberski May 18 '17 at 20:1050unattended-upgrades
lists"origin=Debian,codename=${distro_codename},label=Debian-Security";
and it appears to find relevant packages correctly. Of course it ignores many of them. I've not set up any white or blacklists. – Jon V Sep 15 '17 at 13:1150unattended-upgrades
is indeed stupid and has to be changed for this to work on Raspian. There is noRaspian-Security
. Security updates are not labeled. It is important to add both"origin=Raspbian,codename=${distro_codename},label=Raspbian";
and"origin=Raspberry Pi Foundation,codename=${distro_codename},label=Raspberry Pi Foundation";
to/etc/apt/apt.conf.d/50unattended-upgrades
– user643011 Apr 08 '18 at 00:37"origin=Debian,codename=${distro_codename},label=Debian";
and"origin=Debian,codename=${distro_codename},label=Debian-Security";
with the new lines? – lindhe Oct 03 '20 at 09:13