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:
- Deploy a VPS server. For instance, Ubuntu 24.04. We recommend a Digital Ocean VPS server.
- Create a non-root sudo user. Read our How to Create a Non-Root Sudo User on Ubuntu 24.04 guide.
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.
- SSH to your Ubuntu 24.04 server.
-
Update the server's package information index.
CONSOLE$ sudo apt update
-
Check the current time and timezone.
CONSOLE$ timedatectl
-
Look for the
Local time
andTime zone
values in the output.
Check Available Timezones
Before setting the timezone, you must know the available options.
-
List all available timezones.
CONSOLE$ timedatectl list-timezones
-
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.
-
Use the
timedatectl
command followed byset-timezone
and the desired timezone.CONSOLE$ sudo timedatectl set-timezone <your-timezone>
For instance:
CONSOLE$ sudo timedatectl set-timezone Africa/Nairobi
-
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.
-
Install the
ntp
package if not already installed.CONSOLE$ sudo apt install ntp
-
Review the
/etc/ntp.conf
file to ensure the available NTP servers.CONSOLE$ sudo nano /etc/ntp.conf
-
Enable and start the NTP service:
CONSOLE$ sudo systemctl enable ntp $ sudo systemctl start ntp
-
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:
- Accurate system logs and timestamps.
- Proper functioning of scheduled tasks with
cron
. - Avoidance of time-related errors in applications.
- Synchronization with local business hours.
- 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.