Sunday, July 29, 2018

How to change timezone on Ubuntu 18.04 Bionic Beaver Linux

https://linuxconfig.org/how-to-change-timezone-on-ubuntu-18-04-bionic-beaver-linux

Objective

The objective is to show how to change timezone on Ubuntu 18.04 Bionic Beaver Linux

Operating System and Software Versions

  • Operating System: - Ubuntu 18.04 Bionic Beaver Linux

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

EASY

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Instructions

Change timezone from command line

Check Current Timezone Settings

Let's start by checking the current timezone settings. Use the timedatectl command to show the current timezone and time:
$ timedatectl
                      Local time: Tue 2018-06-06 10:27:34 PST
                  Universal time: Tue 2018-06-06 18:27:34 UTC
                        RTC time: Tue 2018-06-06 18:27:35
                       Time zone: Canada/Yukon (PST, -0800)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
Another alternative to check current timezone on Ubuntu 18.04 system, if the above command from some reason fails, is to check for /etc/localtime symbolic link:
$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 32 Jun  6 10:27 /etc/localtime -> /usr/share/zoneinfo/Canada/Yukon


Show all Available Timezones

In order to change timezone on Ubuntu 18.04, we first need to obtain a timezone name of the timezone we wish to change to. This is usually a CONTINENT/CITY pair.

The timedatectl command comes again handy:
$ timedatectl list-timezone
The timezone list is quite extensive. Scroll page down and up with PgDn and PgUp key respectively.

Alternatively, use grep command to narrow down your search. For example the bellow command will list all Europe cities:
$ timedatectl list-timezones | grep -i europe
Europe/Amsterdam
Europe/Andorra
Europe/Astrakhan
Europe/Athens
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Busingen
...
Europe/Zurich
NOTE:

The timedatectl command is using /usr/share/zoneinfo/ directory to generate the timezone list.

Change Timezone

Now that we know the timezone name we wish to change our timezone settings to, use timedatectl command to set a new timezone.

For example let's change timezone to Europe/Bratislava:
$ sudo timedatectl set-timezone Europe/Bratislava
Using the timedatectl command is a preferred way on how to set a timezone on Ubuntu 18.04. However, note that you can also change timezone settings manually:

NOTE:Changing the timezone using the manual method involving ln command may take minute or so to take an effect.
$ sudo unlink /etc/localtime
$ sudo ln -s /usr/share/zoneinfo/Europe/Bratislava /etc/localtime


Confirm Timezone Change

Lastly, confirm your new timezone settings:
$ timedatectl 
                      Local time: Tue 2018-06-06 19:57:17 CET
                  Universal time: Tue 2018-06-06 18:57:17 UTC
                        RTC time: Tue 2018-06-06 18:57:18
                       Time zone: Europe/Bratislava (CET, +0100)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
Alternatively, confirm a new timezone settings using ls command:
$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 37 Jun  6 20:00 /etc/localtime -> /usr/share/zoneinfo/Europe/Bratislava

Change timezone from GUI

To change timezone from a default GNOME graphical user interface. Navigate to Settings-->Details-->Date & Time:
Current timezone
Current timezone.
Select timezone - Ubuntu 18:04
Use search box to search for a city or find your timezone manually by mouse click.
New timezone is set
New timezone is set.

No comments:

Post a Comment