223

I keep getting this error every time I try to sudo apt update:

Hit:1 ubuntu bionic InRelease
Ign:3 linux/chrome/deb stable InRelease                   
Get:2 /ubuntu bionic-updates InRelease [88.7 kB]   
Get:5 /linux/chrome/deb stable Release [943 B]             
Get:6 http://dl.google.com/linux/chrome/deb stable Release.gpg [819 B]         
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] 
Get:7 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]    
Reading package lists... Done                                 
E: Release file for http://dl.google.com/linux/chrome/deb/dists/stable/Release is not valid yet (invalid for another 2h 45min 28s). Updates for this repository will not be applied.
E: Release file for http://us.archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease is not valid yet (invalid for another 4h 34min 33s). Updates for this repository will not be applied.
E: Release file for http://us.archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease is not valid yet (invalid for another 1h 22min 16s). Updates for this repository will not be applied.
E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 4h 32min 36s). 

Updates for this repository will not be applied.

I've reset my timezone to UTC, but that didn't work.
I also found a different answer where they said I should try

sudo apt-get -o Acquire::Check-Valid-Until=false update

but that didn't work either.
I got the same error both times.

8
  • 6
    Did you compare your current timestamp against the actual UTC time? Do you dual boot? Have you done a time sync up yet to make sure your computer clock is in sync? If you dual boot, it's possible Windows has altered the system clock (also check the time zone in your desktop settings)
    – Thomas Ward
    Nov 28, 2018 at 21:04
  • I dual boot with Windows 10 home and I just time-synced to make ubuntu use local time. Tried updating again but it's still the exact same error unfortunately. Any ideas?
    – user897956
    Nov 29, 2018 at 15:05
  • 3
    Does this answer your question? Getting 'Release is not valid yet' while updating ubuntu docker container
    – rofrol
    Aug 20, 2020 at 14:09
  • Kind of obvious, but restarting Windows solved it for me (dual boot with Ubuntu)
    – Antonio
    Feb 1, 2021 at 9:40
  • In my case, I was running a Virtual Box VM and my laptop shutdown with an update, putting the VM into saved state. When restored, the VM clock was out of synch with host. I simply rebooted the VM and it restored the correct time. Apr 9, 2023 at 23:43

23 Answers 23

305

Run:

sudo hwclock --hctosys 

This command gets the latest time from your Windows machine’s RTC and sets the system time to that.

9
  • 1
    This command gets the latest time.from your windows machines RTC and sets the system time to that
    – rosterloh
    Aug 29, 2019 at 22:34
  • 12
    worked for me.. my Docker Desktop uses WSL2 underneath, and sometimes the clock drifts (a lot) between the Ubuntu and the Windows host machine. This command helps solve that issue.
    – Frederik
    Jun 18, 2020 at 6:53
  • 1
    This worked. But if you are using WSL, you need to restart it. Thanks!
    – nwaweru
    Oct 1, 2022 at 9:56
  • 2
    This command can be shortened to just sudo hwclock -s. From the command help menu ( hwclock -h) options -s and --hctosys are the same: -s, --hctosys set the system time from the RTC.
    – razzak
    Dec 26, 2022 at 15:05
  • 1
    If you are using WSL on Windows, after syncing the Windows system time. Shut down WSL by typing wsl --shutdown then boot up the distro again by typing wsl in the command prompt or Windows terminal.
    – FreeMind
    Apr 24, 2023 at 21:39
84

This is a timezone issue. Try restarting your Docker host. It worked for me.

7
  • 3
    Where did you get the impression that this is docker-related?
    – guntbert
    Nov 26, 2019 at 16:28
  • 2
    @guntbert This answer looks OK to me. Maybe he got the idea that this is docker related from this question: Getting 'Release is not valid yet' while updating Ubuntu docker container
    – karel
    Nov 26, 2019 at 16:39
  • 5
    For Windows users having Docker with wsl backend: I also needed to reboot wsl using wsl --shutdown and then rebooting docker host.
    – Guido
    May 17, 2021 at 7:51
  • 3
    This helped me on podman, restarted and worked Sep 15, 2021 at 17:11
  • In my case, it was a timezone problem - my Windows automatically sets wrong hour when it starts (I was trying to fix it many times but it seems to be unfixable without system reinstallation).
    – maciejwww
    Mar 2, 2022 at 22:15
36

You can use this temporary workaround, given by leon-strong:

apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update

See the bug report https://github.com/microsoft/WSL/issues/4114 for more details.

4
  • 3
    apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update will work around it temporarily.
    – karel
    Mar 2, 2020 at 16:12
  • apt-get -o Acquire::Check-Valid-Until=false update was enough, and I had the same error as the one in the question. I found this shorter version without -o Acquire::Check-Date=false for a slightly different error. It is the accepted answer there, and I guess that the -o Acquire::Check-Date=false is not needed here either. Mar 28, 2021 at 20:18
  • sudo apt-get -o Acquire::Check-Valid-Until=false update should be changed to this: sudo apt-get -o Acquire::Max-FutureTime=86400 update
    – SUF
    Apr 22, 2021 at 10:52
  • This one worked when I was trying to build a container using podman. I didn't try the shorter version though.
    – Tuhin
    Jun 15, 2022 at 14:43
29

Tested on ubuntu 18.04 server:

  1. check BIOS date-time, check also the coin cell in the motherboard and replace if needed.
  2. restart. Execute command date to verify that date time is correct.
  3. execute sudo apt update again. Problems are gone.
2
  • 1
    It works for me, I have Ubuntu and Windows dual boot, as you probably know dual boot has issues with the time when you change system (I know how to fix it by changing timedatectl set-localrtc 1, but I don't feel I like doing so because normally I only stick to Ubuntu). So in my Windows I have build in Ubuntu bash, however as the time changes when I switch to Windows, and when I sudo apt update on Ubuntu inside Windows, it gets error, until I re-change the time it appears normal. Thanks.
    – Negrito
    Jun 19, 2019 at 13:22
  • #3 actually worked for me. I ran a apt update command before systemd-timesyncd.service had a chance to update the clock. Looking through a few Google-suggested answers gave the service a chance to update the clock and my second apt update worked as expected.
    – iAmJeff
    Dec 5, 2021 at 7:24
29

In my case:

  • Microsoft Windows [Version 10.0.19041.630];
  • WSL version 2;
  • Ubuntu-20.04;

The date command reports a wrong date and time. I used the following:

sudo apt install ntp 
sudo service ntp restart 

Then the date command reports the correct data and time. sudo apt update now can work.

1
  • 1
    Didn't work for me
    – synek317
    Nov 27, 2021 at 12:51
25

I have faced the same issue. I solved this issue by installing ntp

apt install ntp

and select your timezone while installing.

if you have already installed ntp, then select your correct timezone by using the following command.

dpkg-reconfigure tzdata
3
  • 7
    none of the other solutions helped; you saved my day Oct 8, 2020 at 7:10
  • 1
    I had to set my timezone with tzdata and then go into "Settings" --> "Date & Time" and set the correct time before I was able to update. Thank you! Oct 4, 2022 at 22:13
  • 1
    This works for me on the 28 August, 2023. Host OS: Windows 11, WSL: 2, WSL Distro: Ubuntu 20.04.6 LTS Aug 28, 2023 at 2:32
9

In my case, the root of the problem was that I was dual-booting between Windows 10 and Ubuntu 18.04, and each OS interprets the time stored in the RTC differently (local time for Windows, UTC for Ubuntu). My fix was to change Ubuntu to interpret the time as local time by running the following command:

timedatectl set-local-rtc 1

I found this solution in another AskUbuntu thread.

Edit: Since the time of my original answer, I have decided that it's better to switch Windows to UTC instead of switching Ubuntu to local time. This is done with a single registry key:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
  "RealTimeIsUniversal"=qword:00000001
1
  • it works for me so that I have upvoted. I hope the time doesn't change if i use windows. @carlton
    – Pranav
    Jul 24, 2019 at 17:18
8

Install the ntp package:

sudo apt install ntp
sudo echo "ip_adress" >> /etc/ntp
sed -i 's/pool /#pool /g' /etc/ntp.conf
sudo systemctl restart ntp.service

Then:

sudo apt update
4
  • 1
    thanks, it works for me but I think you should explain your answer better
    – clay
    Sep 20, 2019 at 16:17
  • is 'ip_adress' correct? it looks like a typo
    – Erik
    Oct 7, 2019 at 20:04
  • I have a Permission denied for echoing ip_address in /etc/ntp :// Nov 7, 2019 at 9:08
  • Ip adress is ntp server's ip adress. You can write ntp.yourntpserver.com Nov 8, 2019 at 18:32
6

If anyone facing similar issue in WSL2 then the culprit might be the wrong system date (check it with date command once). You can follow this github issue for updates. Following command is from the same github discussion which worked for me to resolve the issue for now.

sudo hwclock -s
1
  • doesn't sync the time for me
    – Nearoo
    Oct 15, 2022 at 16:30
5

The solutions above didn't work for me. I had to change manually the date with
date -s '2021-03-18 12:34:12'

Then, sudo apt-get update worked just fine

1
  • 1
    Thx! Actually this was the only working solution for me, as I couldn't do anything else to change the date.
    – Kulgar
    Jul 19, 2023 at 12:42
4

None of the previous answers worked for me. I was getting this error running Ubuntu in in a virtual machine using Vagrant & Virtualbox.

This was the solution that worked for me:

sudo timedatectl set-ntp off
sudo timedatectl set-ntp on
2
  • 1
    I had the same problem running xubuntu 20.04 in a virtualbox. my issue was i restored to a very old date, so i was facing this issue. the command solved my problem alhamdulillah. Jan 14, 2021 at 16:12
  • 1
    Solved my problem as well, same state and issue (my local clock was being read as UTC in the VM)
    – Cireo
    Mar 1, 2021 at 21:17
2

I started getting this error in an ubuntu 18.04 VirtualBox VM running on a Windows 10 host. It started happening after installing some updates. Then I noticed that the date in ubuntu was now behind the current, real date by over a month. Simply restarting the VM caused the date to be fixed and the update error to go away.

2

I fixed this by running

ntpdate pool.ntp.org

Please google for your own ISPs ntp server.

1

If the problem originates from a dead CMOS battery, you can synchronize the hardware clock to the current system time as a stopgap measure. This requires doing the opposite of @rosterloh's answer:

# hwclock --systohc

Note that systohc, and not hctosys, is being passed here.

1

I don't know what the origin of this problem was, but

sudo service ntp restart

solved all things

1

I had the same thing happen to me and the problem solved itself in a few minutes on my Raspberry Pi.

It was due to incorrect system time, but I didn't have to do anything to fix it. I do not have ntpd or chronyd running on this system. I don't believe there is a battery in a Raspberry Pi to keep the motherboard clock running. I just had to wait for the systemd-timesyncd.service to finish.

I think ultimately the answer to your situation is to verify your system clock is at least close to the correct time, whether it involves getting one of the NTP services to update your system clock or manually setting the time. For reference, the date command format to set the system time is:

sudo date [MMDDhhmm[[CC]YY][.ss]]

If your system runs chronyd, chronyc -n sources -v will show you the time servers you're polling. If you're running ntpd, ntpq -np. There should be an asterisk, *, next to an IP address. That's the time server you're synchronized with. (It should not be an address that starts with 127, though!) If there is no asterisk in the first or second column, you'll need to somehow set the time manually. You can try the hwclock command or set the time with date. Please be aware that even if you're running ntpd or chronyd these services can take up to several minutes to update the system clock, unless you've configured them to either immediately step the time or rapidly poll the time servers.

Details of My Situation

On December 4, 2021, I pulled my Raspberry Pi 400 out of it's backpack with the intention of updating the software. After it booted I immediately opened a terminal and ran sudo apt update. The error I received was invalid for another 77d .... There was actually two of these errors listed and the second one had a different day value. Unfortunately, I cannot scroll back far enough in my terminal to get the exact error messages.

In the time it took me to run a Google search and find this StackExchange question, the systemd-timesyncd.service updated the system clock. Looking in the logs I can find this sequence of events. The first sudo apt update produced the error messages. The second performed as expected.

Sep 17 08:48:47 rp400 sudo[6322]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/apt update
[...]
Sep 17 08:48:52 rp400 systemd[1]: systemd-fsckd.service: Succeeded.
Dec 04 23:21:04 rp400 systemd-timesyncd[353]: Synchronized to time server for the first time 163.237.218.19:123 (2.debian.pool.ntp.org).
Dec 04 23:21:05 rp400 dhcpcd[430]: wlan0: leased xxx.xxx.xxx.xxx for 86400 seconds
[...]
Dec 04 23:25:21 rp400 sudo[20143]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/apt update

A quick status check of the timesyncd service confirmed the September to December time jump.

pi@rp400:~ $ systemctl status systemd-timesyncd.service
  systemd-timesyncd.service - Network Time Synchronization
[...]
   Active: active (running) since Fri 2021-09-17 08:48:23 CDT; 2 months 17 days ago
[...]
   Status: "Synchronized to time server for the first time 163.237.218.19:123 (2.debian.pool.ntp.org)."
[...]
Sep 17 08:48:22 rp400 systemd[1]: Starting Network Time Synchronization...
Sep 17 08:48:23 rp400 systemd[1]: Started Network Time Synchronization.
Dec 04 23:21:04 rp400 systemd-timesyncd[353]: Synchronized to time server for the first time 163.237.218.19:123 (2.debian.pool.ntp.org).

I can see the same thing happening to a virtual host that was suspended for a long time.

0

I also experienced this problem, while trying out the new Linux subsystem for Windows 10. I was using Ubuntu and had trouble installing apache2, so I figured I needed to update. Carlton is correct, there is an issue with the miscommunication of the dates between Windows 10 and Ubuntu.

I solved this by using the "date" command on windows command prompt to change the date to the current date.

0
E: Release file for http://http.kali.org/kali/dists/kali-rolling/InRelease is not valid yet (invalid for another 3h 29min 24s). Updates for this repository will not be applied.

Set system time properly then this issue will be fixed

sudo apt-get update
0

Similar problem happened to me. My laptop has dual boot with windows 10. Time gets changed each time I open windows os. I have to open BIOS and change time and date. As per my knowledge it is due to invalid system time. I think thats the issue of CMOS cell. But the time in Ubuntu works fine. You can try:

  • Change CMOS cell.
  • Change Time and date in BIOS then try updating.

Then run command in ubuntu

sudo apt-get update
0

I had this problem on windows. I needed to install ubuntu from the Microsoft store to get access to the linux subsystem.

  • This issue arises because the time goes out of sync when I shut my laptop's lid
sudo apt-get install ntp
sudo sntp time.nist.gov # replace ntpdate with sntp to make it work

Should fix it when running in ubuntu (it syncs the time).

0

I encountered same problem on my Windows 10 and spent hours on it. Finally, I made the time zone on my Ubuntu === to the time zone on my windows 10 and the update command worked.

0

Running any of these commands should fix errorthe problem:

apt clean

or

apt-get clean

-1

Try running the following command

sudo systemctl restart ntp.service && ntpq -p

OR to edit manually, run

nano /etc/ntp.conf and add/edit the following lines:

server 0.ubuntu.pool.ntp.org<br>
server 1.ubuntu.pool.ntp.org<br>
server 2.ubuntu.pool.ntp.org<br>
server 3.ubuntu.pool.ntp.org

You must log in to answer this question.