Whether you are a system administrator, network administrator, or a normal user under a Linux operating system, it is important to ensure your system is set to the correct date and time in regard to your location.
For instance, your prowess in Linux administration might take you to different time zones and locations. Under such circumstances, you might need to update your Linux system with the correct date and time values so that you are not caught off guard during important activities like project presentations.
Also, some programs that run under Linux reference the system date and time values as part of their input and output data. The misrepresentation of such values can yield logical consequences.
[ You might also like: How to Set Date, Time and Timezone in RHEL 8 ]
Rocky Linux and Alma Linux are such server-based systems whose date and time values need to be set correctly in regards to the location and timezone of the OS user. Also, the execution of these systems’ cronjobs references the set date and time.
Check Date and Time in Rocky Linux
The main command we are going to reference for both Rocky Linux and AlmaLinux is timedatectl – which shows the current date and time statuses.
$ timedatectl
Alternatively, you could use the following command.
$ timedatectl status
Setting Timezone in Rocky Linux
After checking on the status of the date and time via the command line, the first step is to set the time zone in regard to your location. These two Linux systems make this step easy for you so that you do not need to go to Google to determine your current time zone.
You can trace and pick your preferred timezone from the following command.
$ timedatectl list-timezones
The above command reveals a scrollable list of supported time zones. For instance, we might want to use America/Aruba time zone. The command for setting timezone is as follows:
$ sudo timedatectl set-timezone America/Aruba
Check on the time and date status to be sure the new time zone value was implemented successfully.
$ timedatectl status
As highlighted, the time zone change was a success.
How to Set Time in Rocky Linux
The second step is to set time on your AlmaLinux and Rocky Linux systems. Changing time and date on such systems is not as straightforward as it was with the case of changing the timezone.
We have to first consider and acknowledge the viability of the Network Time Protocol (NTP). We cannot permanently change the date or time on Linux without temporarily disabling the Chrony daemon responsible for NTP.
$ sudo systemctl stop chronyd
From here, we can now change the time on our system to a value of our choice. The time value should be in the format hh:mm:ss
as shown.
$ sudo timedatectl set-time 00:40:00
We can check to see if the set time was implemented.
$ timedatectl status
How to Set Date in Rocky Linux
The final step is to set a date on your AlmaLinux and Rocky Linux systems. With NTP still inactive/disabled, we can set the date on our systems. The date value should adhere to the format yyyy-mm-dd
as shown.
$ sudo timedatectl set-time 2021-12-14
Check to see if the set date was implemented:
$ timedatectl status
Start the NTP service and check on its status.
$ sudo systemctl start chronyd
As you might have noticed, changing the timezone on AlmaLinux and Rocky Linux does not require stopping the NTP service but changing date and time do. It is the main tip and trick you have to master in this tutorial.