In the zone

The default time zone for Raspbian – which is the Linux distribution I installed on the Raspberry Pi – is UTC; this is not terribly convenient for somebody living in Illinois, so the other day I set about changing the Pi’s time zone to CST.

This proved…interesting.

There are a great many ways to set the time zone in Linux. One is user-specific, the others are global but don’t always work on all platforms. Some work, but disappear after a while.

Method #1

Run the tzselect utility. It will ask some questions, then spit out a line that looks like this:

TZ='America/Chicago'; export TZ

Add this line to ~/.profile and you’re done.

This only changes the time zone for the current user. (How many Raspberry Pi machines have multiple user accounts?) The system time zone remains UTC. And support-forum chatter suggests fooling with the TZ environment variable is deprecated.

Method #2

The system time is controlled by /etc/localtime. Overwrite it with the appropriate file from /usr/share/zoneinfo:

sudo cp /usr/share/zoneinfo/America/Chicago /etc/localtime

On some distributions, /etc/localtime is overwritten on system restart. Oops.

Other options

I’ve seen these proposed:

  • Edit /etc/rc.conf
  • Run tzset or tzconfig
  • (On Raspbian) run sudo dpkg-reconfigure tzdata

I went with the /etc/localtime method. It may not be the officially-blessed method – I’m not convinced that such a thing even exists – but it works.