Howto setup and change the timezone on Debian 8 Linux systems
In this mini post, I’ll show you how to set or change the time zone on Linux systems (Debian Family “Debian 8 “jessie” and earlier – Ubuntu Linux”). Setting up the correct time zone for your Linux server is a simple but very important task. All your Linux machines must be have the correct time zone to facilitate the administrations and monitoring tasks. Setting up the correct time zone is a critical task for Linux machines that serving e-commerce applications and payment methods.
If you forgot to set the proper timezone or your Linux systems timezone is pointing to the wrong timezone, here I’ll show you how to set and change your Linux server’s timezone.
There are several different ways to manage time in Linux. This quick tip will show you how to quickly change the local time to the correct time zone for the server in three methods.
Method 1: Changing The Current Timezone Using /etc/localtime File.
This method is available in all Linux distros “All Linux families RPM, Debian, Suse, etc…”, and not just for debian Linux. Simply all I need to do is replacing the existing localtime file in “/etc/localtime” with the correct time zone file from any directory in “/usr/share/zoneinfo/“.
For this example, assume that your current timezone is EET “Africa/Cairo” as shown below:
# date Fri Oct 7 14:27:50 EET 2016
Now, you want to change it to JST “Asia/Tokyo“, All the required from you is replacing the existing “/etc/localtime” file with “/usr/share/zoneinfo/Asia/Tokyo” as the following:
# rm /etc/localtime # cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
Now, check the new time zone for your server, run the following command:
# date Fri Oct 7 21:45:43 JST 2016
Perfect !!, My server has the correct timezone and it save to monitor and serving e-commerce applications on it.
One last thing, it’s preferred to set the correct timezone in the “/etc/timezone“, run the following command:
# echo "Asia/Tokyo" > /etc/timezone
The above command is a preferred one, you safely can ignore it.
Here’s a listing for all timezone files in “/usr/share/zoneinfo/“, run the following command:
# ls -F /usr/share/zoneinfo/ Africa/ Australia/ Cuba Etc/ GMT-0 Indian/ Kwajalein MST7MDT Portugal ROC US/ America/ Brazil/ EET Europe/ GMT+0 Iran Libya Navajo posix/ ROK UTC Antarctica/ Canada/ Egypt GB Greenwich iso3166.tab MET NZ posixrules Singapore WET Arctic/ CET Eire GB-Eire Hongkong Israel Mexico/ NZ-CHAT PRC Turkey W-SU Asia/ Chile/ EST GMT HST Jamaica Mideast/ Pacific/ PST8PDT UCT zone.tab Atlantic/ CST6CDT EST5EDT GMT0 Iceland Japan MST Poland right/ Universal Zulu
For other country timezones, browse the “/usr/share/zoneinfo” directory and it’s sub-directories.
Hint: 1.You can use either "cp" or "ln" or "ln -s" to replace the existing /etc/localtime with the correct time zone file from /usr/share/zoneinfo.
Method 2: Changing The Current Timezone in Debian / Ubuntu using tzdata.
For Debian Linux Family “Debian 8 “jessie” / 7 and earlier – Ubuntu Linux” there is another method to change the timezone beside the above method “the general Linux method“. Debian Linux family has a package called “tzdata” shipped by default with all installation types, we can use “dpkg-reconfigure” to configure this package to us the correct timezone in all Debian systems.
For this example, assume that your current timezone is EET “Africa/Cairo” as shown below:
# date Fri Oct 7 17:54:58 EET 2016
Now, you want to change it to JST “Asia/Tokyo“, All the required from you is running the below command and select your “Geographic area” then select your “Time zone“, as the following:
# dpkg-reconfigure tzdata
Once it finishes, it outputs the following data:
# dpkg-reconfigure tzdata Current default time zone: 'Asia/Tokyo' Local time is now: Sat Oct 8 01:01:55 JST 2016. Universal Time is now: Fri Oct 7 16:01:55 UTC 2016.
Verify the new settings by typing the following command:
# date Sat Oct 8 01:03:13 JST 2016
Method 2 is an interactive method, but what if I need to set your Debian timezone with a non-interactive method use the following method:
Method 3: Non-Interactive Method to Change The Current Timezone in Debian / Ubuntu using tzdata .
For Debian Linux Family “Debian 8 “jessie” / 7 and earlier – Ubuntu Linux” we can use the non-interactive method to change the timezone for Debian Linux systems.
Debian systems has a package called “tzdata” shipped by default with all installation types, we can use “dpkg-reconfigure” to configure this package to us the correct timezone in all Debian systems.
For this example, assume that your current timezone is EET “Africa/Cairo” as shown below:
# date Wed Nov 2 12:35:46 EET 2016
Now, you want to change it to JST “Asia/Tokyo” using a non-interactive command, All the required from you is to determine the time zone you want, then run the below commands, as the following:
# echo "Asia/Tokyo" > /etc/timezone
Then run the following command, the command and it’s outputs are as the following:
# dpkg-reconfigure -f noninteractive tzdata Current default time zone: 'Asia/Tokyo' Local time is now: Wed Nov 2 19:36:08 JST 2016. Universal Time is now: Wed Nov 2 10:36:08 UTC 2016.
Verify the new settings by typing the following command:
# date Wed Nov 2 19:38:41 JST 2016
Hints: 1. The importance of the non-interactive method comes when you want to change the timezone using a shell script or a configuration management tool "like ansible". 2. The non-interactive method needs you to know the timezone first like "Asia/Tokyo" to add it manually to "/etc/timezone" file.
If You Appreciate What We Do Here On Mimastech, You Should Consider:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.
[…] up timezone on Debian / Ubuntu Linux […]
I see your page needs some unique & fresh articles.
Writing manually is time consuming, but there
is tool for this task. Just search for; Digitalpoilo’s tools
Thanks for your advice; however I’m writing technical articles which “I think” are understood by all users searching for info from these articles. Again I’ll consider you advice for improving my technical blog.