How to Set Timezone on Ubuntu 24.04

Introduction

Timezones help you organize your day, manage appointments, and ensure smooth operations. Every geographic region has a unique timezone. Correctly setting your timezone is essential for accurate system logs, cron jobs, and business logic. If your server's timezone is incorrect, it could lead to confusion, missed deadlines, or errors in time-sensitive applications.

This guide shows you how to set the timezone on Ubuntu 24.04 and synchronize your server's time with Network Time Protocol (NTP).

Prerequisites

Before you begin:

Check the Current Time and Timezone

To start, you need to check your current system time and timezone. This helps you understand if there's a need to change it.

  1. SSH to your Ubuntu 24.04 server.
  2. Update the server's package information index.

    CONSOLE
    $ sudo apt update
    
  3. Check the current time and timezone.

    CONSOLE
    $ timedatectl
    
  4. Look for the Local time and Time zone values in the output.

Check Available Timezones

Before setting the timezone, you must know the available options.

  1. List all available timezones.

    CONSOLE
    $ timedatectl list-timezones
    
  2. Scroll through the list or use grep to search for your specific timezone.

    CONSOLE
    $ timedatectl list-timezones | grep <part-of-timezone>
    

Set Timezone

After identifying the correct timezone, you can set it using the following steps.

  1. Use the timedatectl command followed by set-timezone and the desired timezone.

    CONSOLE
    $ sudo timedatectl set-timezone <your-timezone>
    

    For instance:

    CONSOLE
    $ sudo timedatectl set-timezone Africa/Nairobi
    
  2. Verify that you've set the correct timezone.

    CONSOLE
    $ timedatectl
    

Synchronize Time with NTP

NTP ensures your system time is accurate by synchronizing it with internet time servers.

  1. Install the ntp package if not already installed.

    CONSOLE
    $ sudo apt install ntp
    
  2. Review the /etc/ntp.conf file to ensure the available NTP servers.

    CONSOLE
    $ sudo nano /etc/ntp.conf
    
  3. Enable and start the NTP service:

    CONSOLE
    $ sudo systemctl enable ntp
    $ sudo systemctl start ntp
    
  4. Verify that NTP is active and synchronizing time.

    CONSOLE
    $ timedatectl status
    

Explore the Benefits of Setting the Correct Timezone

Setting the correct timezone offers various benefits:

  1. Accurate system logs and timestamps.
  2. Proper functioning of scheduled tasks with cron.
  3. Avoidance of time-related errors in applications.
  4. Synchronization with local business hours.
  5. Compliance with regional regulations.

Conclusion

Setting the correct timezone on your Ubuntu 24.04 server ensures accurate system operations and seamless integration with local time-based tasks. You learned how to check the current time and timezone, list available timezones, set the correct timezone, and synchronize time using NTP. This knowledge will help you manage your server efficiently, avoiding potential issues caused by incorrect time settings.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js