How to Set Linux Timezone to CST (Asia/Shanghai) in Minutes
This guide explains three methods to change a Linux system's timezone to China Standard Time (CST, Asia/Shanghai), covering the recommended timedatectl command, manual /etc/localtime linking, and a temporary TZ environment variable, with step‑by‑step commands and verification tips.
In Linux you can change the system timezone to CST (China Standard Time, GMT+8, also known as Asia/Shanghai) by following these steps.
Method 1: Using timedatectl (recommended for most modern distributions)
Check current timezone: timedatectl Output shows something like:
Local time: Fri 2024-11-29 10:00:00 CST
Universal time: Fri 2024-11-29 02:00:00 UTC
RTC time: Fri 2024-11-29 02:00:00
Time zone: Asia/Shanghai (CST, +0800)List available timezones: timedatectl list-timezones | grep Shanghai The result should contain Asia/Shanghai .
Set timezone to CST (Asia/Shanghai): sudo timedatectl set-timezone Asia/Shanghai Verify the change: timedatectl The output should display Time zone: Asia/Shanghai (CST, +0800) .
Method 2: Manually linking /etc/localtime
Backup the existing configuration: sudo mv /etc/localtime /etc/localtime.bak Link to the CST zone file:
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeVerify: date The output should show the current time in CST (GMT+8).
Method 3: Temporary change via environment variable
If you only need a temporary adjustment, set the TZ variable in the current session: export TZ="Asia/Shanghai" Check with: date Note: This change lasts only for the current session and is lost after a reboot or opening a new terminal.
Important notes
Using timedatectl is the recommended approach for modern Linux distributions.
Make sure the system clock (UTC) is correct; the timezone only affects how the time is displayed.
Manually linking /etc/localtime is useful for older systems that do not support timedatectl.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
