How to set timezone on Ubuntu? [SOLVED]


Ubuntu

Author: Omer Cakmak
Reviewer: Deepak Prasad

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:

set timezone


Select location from map for new time zone:

How to set timezone on Ubuntu? [SOLVED]


Then the new time zone is set:

How to set timezone on Ubuntu? [SOLVED]


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:

How to set timezone on Ubuntu? [SOLVED]


Then the time zone is selected:

How to set timezone on Ubuntu? [SOLVED]

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

Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment