How-To

How to Set the Time Zone in Linux

Clock

An important aspect of running any UNIX computer is making sure the time and time zone is configured correctly. Let’s look at how to set the time zone in Linux.

Time zones can get complicated, especially if you and your Linux server are located in different zones.

Intended to help people keep daytime and evening hours straight anywhere in the world, time zones don’t really matter to a computer. It’s usually best to set your Linux time zone to match yours or the one most of your users observe.

So, you may need to set the time zone in Linux to ensure to set the correct time. Fortunately, it’s easy to configure the time zone on Linux even after installation. Here’s how.

Why Does the Time Zone Matter in Linux?

There are a number of tasks that Linux handles according to a schedule. These can include running backups or checking for software updates. Ideally, these should run when your Linux computer isn’t being used as much, after working hours. It’s much easier to coordinate this if you set the time zone according to your own.

Inevitably, you’ll need to examine log files for potential troubles. Understanding what’s happening when is a much simpler task when 5 p.m. means the same thing to you and the Linux server. Hence one more reason to make sure the time zones match.

Checking the Configured Time Zone in Linux

Linux offers a couple of ways to check the time zone. The oldest way is to check where the system’s /etc/localtime points. This is the file location set when you configure the time zone. In the early days of system administration, this was set by manually creating a symbolic link from the right time zone file to /etc/localtime.

You can check this by running the command ls -l /etc/localtime from the terminal.

ls command to check time zone

In this example, you can see the time zone is set to Central Standard Time, or UTC-6.

The more modern method uses the timedatectl command, which is also used on today’s Linux systems to set the time zone.

timedatectl output

Once again, we see the time zone is set for CST.

How to Change the Time Zone on Linux

We can use the same timedatectl command to change the time zone. First, though, you will need to know the correct long name of the time zone you wish to use. For several years, Linux has used long names based on the region and city to define time zones.

List them by issuing the command timedatectl list-timezones from the terminal. The output will be quite lengthy, so page through it using the spacebar. After you’ve identified the correct choice, you can press q to stop the command’s list.

timedatectl list-timezones

Let’s say we want to set the time zone according to the local time in New York City. We’ll note a listing for America/New_York, which is what we want to use. We can set it with the command sudo timedatectl set-timezone America/New_York. We then verify the change took effect using the previous empty timedatectl command.

how to set the time zone in linux using timedatectl

That’s all there is to it, but what if your Linux server is older and doesn’t have timedatectl?

It’s slightly more complicated to set a time zone in Linux without timedatectl, but still easy.

To Use Manual Symbolic Link Method on Linux

  1. Identify the correct time zone file in /usr/share/zoneinfo.
    listing time zone files
  2. Remove the previous symbolic link from /etc/localtime.
    sudo rm localtime
  3. Create a symbolic link from the correct time zone file to /etc/localtime.
    ln localtime
  4. Verify the change by running the date command from the terminal. The output will show the current time zone, which I have changed back to Central Standard Time.
    output of date command

Using Gnome Settings to Configure the Time Zone

One last note, in case you manage your Linux computer using Gnome or some other GUI. The settings app for Gnome, KDE, and other major desktop environments will provide a way to set your Linux time zone.

To Configure Time Zone Using Gnome Settings

  1. In Gnome or KDE, open Settings > Date & Time or its equivalent.
    Gnome Date and Time Settings
  2. Click on Time Zone.
    Gnome Time Zone Map
  3. Choose the appropriate selection on the map that appears.

Effectively Managing Your Linux Computer

Running a Linux computer properly involves a number of administrative tasks. None of them are difficult, but it can be overwhelming for a new Linux system administrator to manage.

Whether it’s changing your Linux password or knowing how to search for files, we’ve got you covered.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

 

To Top