236

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.

zx485
  • 2,865

23 Answers23

318

Run:

sudo hwclock --hctosys 

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

Melebius
  • 11,750
rosterloh
  • 3,281
86

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

Harshal
  • 969
  • 6
  • 2
41

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.

Eliah Kagan
  • 119,640
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.
Angelito
  • 391
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.

Zanna
  • 72,312
Simon Law
  • 391
27

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
10

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

Carlton
  • 311
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
7

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
anonymous2
  • 4,325
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

A. Attia
  • 151
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
badsyntax
  • 191
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.

snark
  • 301
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

Zanna
  • 72,312
bolgari
  • 11
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.

iAmJeff
  • 111
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
Kulfy
  • 18,154
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).

A H
  • 121
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
Abhay Patil
  • 2,793
mahy4r
  • 1