`timedatectl set-timezone` doesn't update `/etc/timezone`

11,846

timedatectl updates /etc/localtime, which is the documented way of setting the default timezone in most Linux-based environments (along with its override, the TZ environment variable, which is the only POSIX-defined way of specifying the timezone).

/etc/timezone appears to be mostly Debian-specific (including derivatives). On Debian systems, timedatectl set-timezone also updates /etc/timezone.

If you manually update /etc/timezone, you should also update the /etc/localtime symlink (and make sure you keep the latter a symlink). Updates to /etc/localtime appear to be taken into account by (most?) desktop environments, so there’s no need to use environment-specific tools to update the timezone.

If you’re running Debian, you should use dpkg-reconfigure tzdata to configure the default timezone; that updates /etc/localtime and /etc/timezone as above, and it also updates the selected timezone in the debconf database (which serves as the default when configuring tzdata). If you don’t do this, the next time tzdata is updated, the timezone will be restored to the value in the debconf database. dpkg-reconfigure tzdata also takes care of updating the SE Linux context, if you’re using SE Linux.

Share:
11,846

Related videos on Youtube

Tom Hale
Author by

Tom Hale

Updated on September 18, 2022

Comments

  • Tom Hale
    Tom Hale over 1 year

    I expected that timedatectl would update /etc/timezone when changing timezones, but no:

    % sudo timedatectl set-timezone 'Asia/Kuala_Lumpur'
    % cat /etc/timezone
    Asia/Bangkok
    

    Is there a reason that it doesn't? (Bug?)

    If I manually update /etc/timezone to match timedatectl set-timezone, are there any side-effects I should be aware of?

    Is there anywhere else I should consider changing timezone, eg xfce4 panel clock?

    • Stéphane Chazelas
      Stéphane Chazelas almost 6 years
      I don't think many things use /etc/timezone, localtime() and co. don't. if $TZ is not set, what matters is /etc/localtime
  • Stéphane Chazelas
    Stéphane Chazelas almost 6 years
    And to answer Tom's other question, timedatectl is a systemd thing that queries timedated over dbus and timedated derives the name of the timezone (like Europe/London) by doing a readlink() on /etc/localtime. If /etc/localtime is not a symlink, then that name cannot be derived as those timezone definition files don't contain that information.
  • Stéphane Chazelas
    Stéphane Chazelas almost 6 years
    What's an official system software? What do you mean by UNIX? What documentation are you referring to?
  • schily
    schily almost 6 years
    Software delivered with the system. Typical UNIX systems are Solaris, AIX, HP-UX. FreeBSD.
  • Stéphane Chazelas
    Stéphane Chazelas almost 6 years
    I use dpkg-reconfigure tzdata on Debian to configure the system timezone. I assume it does what is needed. It does modify /etc/timezone and /etc/localtime
  • Stéphane Chazelas
    Stéphane Chazelas almost 6 years
    Do any of those systems have a timedatectl command?
  • schily
    schily almost 6 years
    No, but the documented content of /etc/timezone is something like US/Eastern East.Sun.COM #Sun East Coast. Is this what timedatectlsets up?
  • Stéphane Chazelas
    Stéphane Chazelas almost 6 years
    You seem to be referring to the /etc/timezone file used by the sysidtool software on Solaris to build NIS maps. It is specific to Solaris. timedatectl is a systemd utility to interact with its timedated service, which suggests the OP is running a GNU/Linux system using systemd's init framework, more specifically, probably a Debian-based one as that /etc/timezone file is mostly Debian-specific. See also 0pointer.de/public/systemd-man/timezone.html, out-of-date as systemd no longer uses that file even on Debian.
  • Tom Hale
    Tom Hale almost 6 years
    On Debian systems, timedatectl set-timezone also updates /etc/timezone - Hmm, not so on Manjaro (Arch-based). I've let them know.
  • Tom Hale
    Tom Hale almost 6 years
    Thanks @StéphaneChazelas, you may be interested in this answer based on your comment.