Set the Timezone in Ubuntu with timedatectl
The timedatectl command is a powerful tool that can be used to view and change the system’s time and date settings in Ubuntu. It is a part of the systemd system and service manager, and it is a replacement for the old date command.
To use timedatectl, you need to be logged in as a root user or have sudo privileges. Once you are logged in, open a terminal window and type the following command:
timedatectl
This will display the current time and date settings for your system, including the timezone.
To list all of the available timezones, you can use the following command:
timedatectl list-timezones
You can use grep to find your timezone.
timedatectl list-timezones | grep -i <city name>
results for timedatectl list-timezones | grep -i paris
:
Europe/Paris
To set the timezone, you can use the following command:
timedatectl set-timezone <timezone>
For example, to set the timezone to America/New York, you would use the following command:
timedatectl set-timezone America/New_York
Once you have set the timezone, you can use the following command to verify that the change has been made:
timedatectl
The output of this command should now show the new timezone. e.g. before:
Local time: Wed 2023-09-13 00:01:57 UTC
Universal time: Wed 2023-09-13 00:01:57 UTC
RTC time: Wed 2023-09-13 00:01:57
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
After:
Local time: Tue 2023-09-12 20:02:10 EDT
Universal time: Wed 2023-09-13 00:02:10 UTC
RTC time: Wed 2023-09-13 00:02:10
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
In addition to setting the timezone, you can also use timedatectl to enable or disable NTP updates. NTP (Network Time Protocol) is a protocol used to synchronize the clocks of computers over a network. To enable NTP updates, you can use the following command:
timedatectl set-ntp true
To disable NTP updates, you can use the following command:
timedatectl set-ntp false
To verify that NTP updates are enabled or disabled, you can use the following command:
timedatectl status
The output of this command should show the status of NTP updates.
Here are some additional things to keep in mind when using timedatectl:
- The timedatectl command can be used to change the timezone for the entire system, or for a specific user.
- If you are changing the timezone for the entire system, you need to restart the system for the changes to take effect.
- If you are changing the timezone for a specific user, you need to log out and log back in for the changes to take effect.
- NTP updates are usually enabled by default in Ubuntu. However, if you have disabled them, you can enable them using the timedatectl command.
I hope this article has been helpful in explaining how to use timedatectl to set the timezone in Ubuntu and enable NTP updates. If you have any questions, please feel free to ask in the comments :).