In this tutorial, we will show you how to change the timezone on CentOS 8. Timezones are essential for synchronizing the time between different regions and countries, allowing for efficient communication and collaboration. Incorrect timezone settings can lead to issues with server logs, scheduled tasks, and even legal compliance in certain industries. Understanding and managing time zones is a crucial part of maintaining a healthy and efficient CentOS 8 server.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step setting of the correct timezone on a CentOS 8.
Prerequisites
- A server running one of the following operating systems: CentOS 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A stable internet connection.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Change Timezone on CentOS 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update sudo dnf install epel-release
Step 2. Check the Current Timezone.
To begin, it’s essential to determine the current timezone setting of your CentOS 8 system. This can be done using the timedatectl
command:
timedatectl
Output:
Local time: Sat 2021-04-21 21:44:22 UTC Universal time: Sat 2021-04-21 21:46:22 UTC RTC time: Sat 2021-04-21 21:30:33 Time zone: UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no
This command will display the current timezone along with other time-related information such as UTC time and RTC time. Understanding your system’s current state is crucial before making any changes.
Step 3. Set or Change the Timezone on CentOS 8.
To list all available time zones, you can either list the files in the /usr/share/zoneinfo
the directory or use the timedatectl
a command like the below:
timedatectl list-timezones | grep -i europe
Output:
... Europe/London Europe/Luxembourg Europe/Madrid .... Europe/Moscow Europe/Oslo Europe/Paris Europe/German Europe/Prague Europe/Riga Europe/Rome
Once you identify which time zone is accurate to your location, run the following command as sudo
user by indicating your time zone:
sudo timedatectl set-timezone Europe/German
After that, run the timedatectl
command to verify the changes:
timedatectl
Output:
Local time: Sat 2021-04-21 22:44:22 UTC Universal time: Sat 2021-04-21 22:46:22 UTC RTC time: Sat 2021-04-21 22:30:33 Time zone: Europe/German (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no
Step 4. Troubleshooting Common Issues.
Common issues when changing timezones include permission errors or the system not recognizing the timezone. Ensure you have the necessary permissions and that the timezone name is spelled correctly. Logs located in /var/log/messages
can provide insights if any errors occur during the process.
Congratulations! You have successfully changed the timezone. Thanks for using this tutorial set or changing the timezone on your CentOS 8 system. For additional help or useful information, we recommend you check the official CentOS website.