iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⏱️

[Linux/Ubuntu] 5 Ways to Set the Timezone to Japan Standard Time (JST)

に公開
2021/02/28

Environment

I am running Ubuntu 18 in a VirtualBox/Vagrant virtual environment.

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Configuration Methods (5 ways)

If you want to set the same timezone for all users, I personally find the fifth method easy and recommend it.

(1) Modify /etc/localtime

$ cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

By doing just the above, other users will also be set to the same timezone.

(2) Set the TZ Environment Variable

$ export TZ="Asia/Tokyo"

The above setting only applies to the current user.
(You can verify this by setting the environment variable for the current user, switching to root, and then running the uptime command.)

(3) Find the Timezone to Set Using the tzselect Command

tzselect itself is an interactive command for checking timezone values.

As shown above, questions will appear, and you can proceed with the selection by entering numbers and pressing Enter.

By placing the following:

TZ='Asia/Tokyo'; export TZ

in ~/.bash_profile, the timezone for the user in that home directory will be changed.

Alternatively, you can write:

Asia/Tokyo

in /etc/timezone. (This applies to all users.)

(4) Set via tzconfig (or dpkg-reconfigure tzdata)

$ tzconfig
WARNING: the tzconfig command is deprecated, please use:
dpkg-reconfigure tzdata

It seems that tzconfig is no longer available in recent Linux distributions... So let's use the recommended dpkg-reconfigure tzdata.

-- Run this after switching to the root user or using sudo
$ sudo dpkg-reconfigure tzdata

A colorful selection screen like the one below will appear.

By following the selections above, the timezone will be unified for all users.

(5) Set with timedatectl

$ timedatectl set-timezone Asia/Tokyo
$ cat /etc/timezone
Asia/Tokyo

The timezone settings for all users have been correctly applied.

As a side note, you can also use the timedatectl command to check the timezone notation as follows:

$ timedatectl list-timezones | grep -i tokyo
Asia/Tokyo

*grep -i is a command option for searching text while ignoring case.

That's all for today.

GitHubで編集を提案

Discussion