I have created a new application using Ruby on Rails v4.1.0. When attempting to start a server or console on Windows, I am encountering the following error:
$ rails server
Booting WEBrick
Rails 4.1.0 application starting in development on ....
Exiting
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:199:
in `rescue in create_default_data_source':
No timezone data source could be found. To resolve this, either install
TZInfo::Data (e.g. by running `gem install tzinfo-data`) or specify a zoneinfo
directory using `TZInfo::DataSource.set(:zoneinfo, zoneinfo_path)`.
(TZInfo::DataSourceNotFound)
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:196:
in `create_default_data_source'
How can I resolve this error?
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.
Note that there is a bug in Bundler that means there's currently no platform option that will match 64-bit Ruby 3.1 on Windows. The solution here to remove the platforms
option.
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 Rails (up to version 4.1.x) omitted :x64_mingw
from the list of platforms and therefore didn't work correctly on 64-bit Windows versions of Ruby.
I had to add two gems to get the server to start..
gem 'tzinfo-data'
gem 'tzinfo'
Then bundle install.
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.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With