TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows

*爱你&永不变心* 提交于 2019-11-26 17:25:39

Resolving the Error

To resolve this error, you'll need to make sure that the tzinfo-data gem is being included in your Gemfile.

First of all, check your Gemfile to see if there is an existing reference to tzinfo-data. If there isn't already a reference, then add the following line:

gem 'tzinfo-data'

You may find that there is already a line like the following:

gem 'tzinfo-data', platforms: [:mingw, :mswin]

If you are using a 64-bit version of Ruby on Windows, then add :x64_mingw to the list of platforms as follows:

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

Alternatively, you can remove the platforms option altogether.

After doing this, run bundle update at the command line to install the tzinfo-data gem and you'll then be able to start your Rails server or console.


Background

The TZInfo::DataSourceNotFound error is being raised by TZInfo, a dependency of the Active Support component of Rails. TZInfo is looking for a source of time zone data on your system, but failing to find one.

On many Unix-based systems (e.g. Linux), TZInfo is able to use the system zoneinfo directory as a source of data. However, Windows doesn't include such a directory, so the tzinfo-data gem needs to be installed instead. The tzinfo-data gem contains the same zoneinfo data, packaged as a set of Ruby modules.

Rails generates a default Gemfile when the application is first created. If the application is created on Windows, then a dependency for tzinfo-data will be included. However (as of Rails version 4.1.0), this omits :x64_mingw from the list of platforms, so doesn't work correctly on 64-bit Windows versions of Ruby. This should be fixed in future Rails releases.

I had to add two gems to get the server to start..

gem 'tzinfo-data'
gem 'tzinfo'

Then bundle install.

Just put this in your app terminal :

gem install tzinfo-data

then change the gemfile line to :

gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin]

then again in your terminal :

bundle update

That will solve the problem directly.

Add the following line to your Gem File

gem 'tzinfo-data', platforms: [:x64_mingw,:mingw, :mswin]

I had that error when trying to install Redmine in a Docker container:

RAILS_ENV=production bundle exec rake db:migrate

gave me the error because package tzdata was not installed in my Ubuntu image.

apt-get update && apt-get install tzdata -y

did the trick.

Maybe tzinfo is not installed on your system, try to install it:

 gem install tzinfo
 gem install tzinfo-data
Stu Horsfield

I had this problem too and fixed it by adding BOTH the :x64_mingw to the list of platforms for tzinfo-data, AND the gem 'tzinfo' to the gemfile. Then bundle install.

I ran into this issue on macOs Mojave 10.14.5 and I found out that it was something with how my symlink in macOs wasn't reading the correct provided zone info files.

I was able to track this down with where the files should be using the command TZInfo::ZoneinfoDataSource.search_path and that provided the output of ["/usr/share/zoneinfo", "/usr/share/lib/zoneinfo", "/etc/zoneinfo"].

I began looking into /usr/share/zoneinfo and there were files available to read. However rails still wasn't finding them, reading them, executing them..? So I then created a symlink from the other file in /usr/share/zoneinfo.default/ to /etc/zoneinfo (the last path TZInfo looks up)

So finally the command that worked for me to fix this issue was ln -s /usr/share/zoneinfo.default /etc/zoneinfo

Hopefully this information is helpful to someone in the future.

so, the gems didn't quite seem to install properly, i had to do the following

gem 'tzinfo-data' gem 'tzinfo'

then

bundle show to see all gems

bundle gem tzinfo will get you the gem's directory

then, go to that directory. you will need to splice tzinfo-data into tzinfo. in the tzinfo-data file, go to.. local_pathname/tzinfo-data-1.2014.5/lib/tzinfo copy all the contents of this directory into... local_pathname/tzinfo-1.2.1/lib/tzinfo (for me this meant copying 'data' the file and 'data' the directory)

then go to local_pathname/tzinfo-1.2.1/lib and open the file, tzinfo, (not the directory) and add this line require 'tzinfo/data'

this was such a pain to figure out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!