How to Fix Time Issues on WSL Ubuntu: Syncing with NTP

September 14, 2024

When running Ubuntu on Windows Subsystem for Linux (WSL), you may encounter time discrepancies between your Windows and WSL environments. This can lead to confusion, especially if your system clock in WSL is not synchronized with the correct time servers. If you've noticed your WSL Ubuntu clock showing an incorrect time, it's likely because the NTP service is inactive, preventing your system from syncing with network time servers.

In this guide, we'll walk you through how to fix time synchronization issues on your WSL Ubuntu system by enabling the NTP service and ensuring your system clock stays accurate.

Why Is My WSL Ubuntu Time Incorrect?

There are a few common reasons why the time may be incorrect on your WSL Ubuntu system:

  1. System clock not synchronized: The default time settings may not be synced with an NTP (Network Time Protocol) server.
  2. NTP service inactive: Without NTP running, your system won't automatically sync with the correct time.

Let's go through the steps to fix this issue.


Steps to Fix Time Sync Issues on WSL Ubuntu

1. Check the Current Time and NTP Status

First, let's verify the current time and NTP status on your WSL Ubuntu system. You can do this by running the timedatectl command:

timedatectl

This will show you details about your system time, including whether the system clock is synchronized and if the NTP service is active. If the output shows System clock synchronized: no and NTP service: inactive, you'll need to enable NTP to fix the issue.

2. Enable NTP on WSL Ubuntu

If the NTP service is inactive, you need to install and enable it. Run the following commands to install and start the NTP service:

sudo apt update
sudo apt install ntp

Once the installation is complete, enable and start the NTP service:

sudo systemctl enable ntp
sudo systemctl start ntp

3. Verify NTP Status

To ensure the NTP service is running correctly, check its status:

sudo systemctl status ntp

You should see active (running) if the NTP service is working properly.

4. Manually Sync the Time (Optional)

If your WSL Ubuntu system time is still incorrect after enabling NTP, you can manually synchronize it with an NTP server:

sudo ntpdate pool.ntp.org

This command will force a sync with an NTP server and should immediately correct the system time.

5. Confirm Time Sync

Finally, run the timedatectl command again to verify that your system clock is now synchronized:

timedatectl

Look for System clock synchronized: yes in the output, which indicates that your WSL Ubuntu time is now synced with the network time servers.


Why Is Time Synchronization Important?

Time synchronization ensures that your system's time is accurate, which is crucial for various tasks like development, logging, and running time-sensitive applications. Mismatched times between your WSL Ubuntu and Windows environments can lead to errors in applications, missed cron jobs, or incorrect timestamps in logs.


Conclusion

By following these steps, you can easily fix time synchronization issues on your WSL Ubuntu system. Enabling the NTP service ensures that your system time stays accurate and in sync with network time servers, avoiding discrepancies between WSL Ubuntu and your Windows host machine.

Keep your system clock synchronized to prevent potential problems in your development environment, especially when working with time-sensitive applications.


Happy coding! 🎉

Follow Me