The time zone is crucial for many system-related tasks and processes in Ubuntu.
The operating system's own applications and applications installed by users can use this time zone. In a system operating in the wrong time zone, things cannot be expected to progress in a healthy way. Sometimes this time zone should be set for logging, sometimes for a cron task.
In this article, we will explain the steps to set the timezone on Ubuntu.
In Ubuntu, as in many operating systems, the system's time zone is set during installation. But for some reason, it may be necessary to set the timezone value again. Timezone can be adjusted with both GUI and console commands.
Set timezone With GUI
To change the timezone from the GUI, go to Settings > Date & Time > Time Zone. Click on the active time zone information:
Select location from map for new time zone:
Then the new time zone is set:
In this step, time zone information was changed from the GUI quickly and easily.
Set timezone With CLI
In old Ubuntu distributions, time zone setting can be done with the tzdata package, and in new systems with the Timedatectl command.
Method-1: Set with Timedatectl Command
The time zone value is displayed in the terminal with the timedatectl command:
foc@ubuntu22:~$ timedatectl Local time: Wed 2022-12-07 18:55:45 UTC Universal time: Wed 2022-12-07 18:55:45 UTC RTC time: Wed 2022-12-07 18:55:45 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no
Time zone information is written to the following file on the system:
foc@ubuntu22:~$ cat /etc/timezone Etc/UTC
The time zone file under the /usr/share/zoneinfo/ directory is linked to the /etc/localtime file:
foc@ubuntu22:~$ ls -la /etc/localtime lrwxrwxrwx 1 root root 27 Dec 7 19:05 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC
The active time zone information is displayed as UTC. For the time zone information to be defined, time zones are listed with the timedatectl command:
foc@ubuntu22:~$ timedatectl list-timezones Africa/Abidjan Africa/Accra Africa/Addis_Ababa Africa/Algiers ...
This way the list goes on and on. You can search for time zone information with the following command:
foc@ubuntu22:~$ timedatectl list-timezones | grep Istanbul Asia/Istanbul Europe/Istanbul
After this process, what you need to do is to write the found time zone information after the command as follows:
foc@ubuntu22:~$ sudo timedatectl set-timezone Europe/Istanbul
Let's look at the time zone information again:
foc@ubuntu22:~$ timedatectl
Local time: Wed 2022-12-07 22:03:07 +03
Universal time: Wed 2022-12-07 19:03:07 UTC
RTC time: Wed 2022-12-07 19:03:07
Time zone: Europe/Istanbul (+03, +0300)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
New time zone(Europe/Istanbul) information is active. The timezone file content has changed:
foc@ubuntu22:~$ cat /etc/timezone
Europe/Istanbul
And the localtime file is linked with the new time zone:
foc@ubuntu22:~$ ls -la /etc/localtime
lrwxrwxrwx 1 root root 35 Dec 7 22:06 /etc/localtime -> /usr/share/zoneinfo/Europe/Istanbul
Method-2: Set with tzdata Package
If you are using an old Ubuntu distribution or keep changing time zone with tzdata, follow this step. If tzdata is not installed on the system, install it with the following command:
foc@ubuntu22:~$ sudo apt install tzdata -y
The tzdata is then configured:
foc@ubuntu22:~$ sudo dpkg-reconfigure tzdata
From the screen that opens, select the geographic area, click the OK icon:
Then the time zone is selected:
After this process, the time zone value will be changed:
Current default time zone: 'Europe/Istanbul'
Local time is now: Wed Dec 7 22:16:52 +03 2022.
Universal Time is now: Wed Dec 7 19:16:52 UTC 2022.
Summary
In this article, we have changed the time zone value with both the old and the new method. We also explained how to change the time zone with the GUI.
Operating systems used as servers will not always have a GUI. In addition, installing an old package on an operating system with a high version may harm its stability. For this reason, it is recommended to set a time zone with timedatectl.
References
help.ubuntu.com - Changing the Time Zone