tzinfo-data is not present error in Rails [duplicate] - ruby-on-rails

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]

In Gemfile, I added this following line
#tzinfo-data
gem 'tzinfo-data', '~> 1.2021', '>= 1.2021.5'
and then, I commented out the following line
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
and then I simply ran
rails server
and it worked for me successfully.
Here is my full Gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.1"
#tzinfo-data
gem 'tzinfo-data', '~> 1.2021', '>= 1.2021.5'
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.2", ">= 7.0.2.3"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
# Use Sass to process CSS
# gem "sassc-rails"
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end

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

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.

I am using windows and for several days I was not able to solve this problem.
So the solution for our 64 bit platform is to type the following in the terminal:
gem install tzinfo
gem install tzinfo-data
Then afterwards go navigate back to your gem file. In case if you haven't created one create it with rails new xyznameofyours on the terminal.
Then replace the line of code which states something like:
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] or
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
to this:
gem 'tzinfo-data'
gem 'tzinfo'
Only then after your code will work!

It is possible that installing the gem directly via cmd might not solve the issue on Windows OS.
Here is how it did work for me step-by-step;
Inside the Gemfile folder "ctrl-F" and type "platforms"
Find the line gem "tzinfo-data", platforms: %i[ mingw mswin
x64_mingw jruby ]
Remove everything after "tzinfo-data" (comma included)
Final view should be just gem "tzinfo-data" add also gem "tzinfo"
On the terminal, type "bundler update" or "bundle update"
Once it is completed, type "rails s"
Notice: Even after this, if your server starts but can not resolve the default page (additionally ctrl-c / ctrl-pause/break doesn't work), then add webrick instead of puma by adding the gem gem 'webrick', '~> 1.3', '>= 1.3.1'. After that, to run the webrick server you need to type
rails s -u webrick

1-go to gemfile
add the following line without any arrays only that line
gem "tzinfo-data"
then save the file
2- then on cmd type
bundle install
then press Enter
3-then also on cmd type
rails server
then press Enter

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

I've replaced:
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
with:
gem 'tzinfo-data', '~> 1.2021', '>= 1.2021.5'
and it worked fine.
> Blockquote

Related

Cannot find gem even though bundle reports it is installed

I am attempting to install kaminari, but Rails cannot find it or a dependency (I've run into both - currently dependency):
∴ bundle exec rails g kaminari:config
Could not find i18n-1.8.4 in any of the sources
Run `bundle install` to install missing gems.
This is despite it being installed:
∴ bundle info i18n
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
* i18n (1.8.4)
Summary: New wave Internationalization support for Ruby
Homepage: https://github.com/ruby-i18n/i18n
Path: /Users/shawn/.rvm/gems/ruby-2.6.3#refstats/gems/i18n-1.8.4
I first attempted to delete Gemfile.lock. Same result. Then I deleted the refstats gemset and recreated it. Same result. Then I tried bundle install --force and got same result.
I've tried both gem 'kaminari', '~> 1.2' and gem 'kaminari' in my Gemfile.
Any suggestions?
EDIT:
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3', '~> 1.4'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'devise', '~> 4'
gem 'kaminari'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Edit 2:
∴ cat .ruby-version
ruby-2.6.3
I have no .ruby-gemset, but my console is reporting I'm using the right one:
12:36:50 shawn#macbook-pro:~/Documents/uga/refstats (git:master:547a0b4) ruby-2.6.3#refstats
∴
EDIT 3:
Well, the gremlin has disappeared, though I cannot say why. This is what I did:
1) Created new test rails app
2) Bundle install in new gemset
3) Added kaminari to Gemfile
4) Bundle install
5) Generated kaminari config successfully
6) Switch to non-working app, but forget to switch gemset, putting me in rvm with no gemset. Don't notice.
7) Bundle install
8) Notice things get installed, including kaminari. Notice I'm on wrong gemset.
9) Switch to correct gemset.
10) Bundle install (which installs nothing)
11) Generate kaminari config successfully
I really cannot say why it started working, unless installing to the rvm root had some effect. But that's what I did, and it's all working now. Thanks for the time.
Just because the gem is installed on your machine does not mean it is part of your bundle. bundle exec scopes the available gems to only what is included in your Gemfile and those gems dependencies. See if i18n for that version shows up when you run bundle show.

Could not find gem 'rails (= 4.2.5) x86-mingw32' when running rails server

I'm trying to learn Ruby on Rails.
Currently been trying out Rails framework. I've installed it. Create new project in MyBlog folder, but when I try to run:
rails server
I get back an error:
Could not find gem 'rails (= 4.2.5) x86-mingw32' in any of the gem sources listed in your Gemfile or available on this machine. Run `bundle install` to install missing gems.
I've installed bundle as suggested. Had few problems with installing it as well, but I've found a soultion on the internet.
Before bundle install I was getting another error saying that it could not find gem 'sqlite3'
Did someone had similar problem? Can you help me with solving it?
Update:
Content of my Gemfile is:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Errors when try to run 'bundle install':
Try to install the following packages to succeed bundle install
sudo apt-get install build-essential
sudo apt-get install libgmp3-dev
These packages are for Linux environment. Find the alternatives for other environments. Let me know if you got any error.
open file Gemfile.lock, find and delete "x64-mingw32" then run the command:-
$bundle install
Late answer but this happened to me just now.
What worked for me was figuring out I accidently installed an older Ruby version.
In your last screenshot you received a line:
Make sure that `gem install json -v '1.8.3'` succeeds before bundling
This command probably failed due to an older Ruby version, get the latest version here (Assuming you're a windows user) https://rubyinstaller.org/downloads/
P.S
Make sure you remove any previous Ruby / Rails installations.
What you need is a "With DEVKIT" installer, preferably the one they recommend on (starts with "=>").

Rails :TypeError: Object doesn't support this property or method [duplicate]

I installed Rails on my Surface Pro 3 and run into this error after trying to view a page. I have tried several suggestions such as installing rubyracer with libv8 but it didn't help.
TypeError: Object doesn't support this property or method (in
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
Here is my gemfile:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'libv8', '~> 3.16.14.7'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'font-awesome-rails'
gem 'simple_form'
gem 'devise'
Coffee script 1.9.0 doesn't play well with Windows. On my Windows 7 machine, using version 1.8.0 solved this problem.
Add to Gemfile
gem 'coffee-script-source', '1.8.0'
then, run
bundle update coffee-script-source
and restart the server (if needed)
Had the same issue (doing a 'hello world' application of all things...) but couldn't get the coffeescript 1.8.0 fix to work. Found a solution here: http://mech.xyz/how-to-fix-ruby-on-rails-turbolinks-js-coffee-error-windows/
Steps:
Navigate to \app\views\layouts\application.html.erb
Change line 6 from
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
to
<%= javascript_include_tag '**defaults**', 'data-turbolinks-track' => true %>
Did this and it's been working fine now.
Contrary to popular belief, Rails is NOT cross platform compatible as they claim. If it was it would work on windows, out of the box. Like you I have tried every available option.
This was solved using Ruby 2.1.5p273/Rails 4.2.0
I changed execjs to use UTF-8 with jscript, no effect. This was done by editing C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\execjs-2.2.2\lib\execjs\runtimes.rb changing the JScript = block to the following.
JScript = ExternalRuntime.new(
name: "JScript",
command: "cscript //E:jscript //Nologo",
runner_path: ExecJS.root + "/support/jscript_runner.js",
encoding: 'UTF-8' # CScript with //U returns UTF-16LE
)
I also tried installing therubyracer which leads to problems with the libv8 dependency not compiling. I added my python 2.7 install to the windows system path, and installed libv8. Then it said libv8 was installed but when I tried to install therubyracer it said libv8 couldn't be found. I uninstalled libv8 and tried again and it said libv8 couldn't be compiled. That was enough for me to determine that therubyracer was not going to work on windows, so I commented it out of my Gemfile, leaving python 2.7 on my windows system path.
I updated coffee-script-source, by adding the following to my Gemfile
gem 'coffee-script-source', '1.9.0'
After adding coffee-script-source to my Gemfile I ran gem update coffee-script-source , this also didn't solve the problem.
I then installed node.js, this worked for 5 minutes until I generated a new controller, and it was broken again.
Note: After installing node.js you need to open a new command prompt to get the updates to your system path that are setup when node.js installs.
Finally what fixed this problem was to open up the app\assets\javascripts\application.js file and remove the last line which says
//= require_tree .
Lastly run the following command to make sure coffee-script is properly installed in Node.js
npm install -g coffee-script
This is caused by an incompatibility between 64bit Windows and the CoffeeScript gem.
This is indeed a CoffeeScript issue. It only appears to affect 64 bit Windows machines. 32bit Windows is fine.
CoffeeScript occurs in two places by default in Rails:
The default scaffold generator makes a coffee script file.
Turbolinks is CoffeeScript.
The simplest way to fix this is to simply remove the CoffeeScript. You probably don't need it anyway.
Delete the generated coffeeScript file in app/assets/javascripts.
Remove the turbolinks gem from the gemfile, then bundle install.
Edit assets/stylesheets/application.js to delete the turbolinks include.
I found your error look like this
ExecJS::RuntimeError on Windows trying to follow rubytutorial
I fix on my system by un-comment the line // = require_tree in 'assets\javascripts\application.js'
= require_tree

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

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]
In Gemfile, I added this following line
#tzinfo-data
gem 'tzinfo-data', '~> 1.2021', '>= 1.2021.5'
and then, I commented out the following line
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
and then I simply ran
rails server
and it worked for me successfully.
Here is my full Gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.1"
#tzinfo-data
gem 'tzinfo-data', '~> 1.2021', '>= 1.2021.5'
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.2", ">= 7.0.2.3"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
# Use Sass to process CSS
# gem "sassc-rails"
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end
Maybe tzinfo is not installed on your system, try to install it:
gem install tzinfo
gem install tzinfo-data
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.
I am using windows and for several days I was not able to solve this problem.
So the solution for our 64 bit platform is to type the following in the terminal:
gem install tzinfo
gem install tzinfo-data
Then afterwards go navigate back to your gem file. In case if you haven't created one create it with rails new xyznameofyours on the terminal.
Then replace the line of code which states something like:
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] or
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
to this:
gem 'tzinfo-data'
gem 'tzinfo'
Only then after your code will work!
It is possible that installing the gem directly via cmd might not solve the issue on Windows OS.
Here is how it did work for me step-by-step;
Inside the Gemfile folder "ctrl-F" and type "platforms"
Find the line gem "tzinfo-data", platforms: %i[ mingw mswin
x64_mingw jruby ]
Remove everything after "tzinfo-data" (comma included)
Final view should be just gem "tzinfo-data" add also gem "tzinfo"
On the terminal, type "bundler update" or "bundle update"
Once it is completed, type "rails s"
Notice: Even after this, if your server starts but can not resolve the default page (additionally ctrl-c / ctrl-pause/break doesn't work), then add webrick instead of puma by adding the gem gem 'webrick', '~> 1.3', '>= 1.3.1'. After that, to run the webrick server you need to type
rails s -u webrick
1-go to gemfile
add the following line without any arrays only that line
gem "tzinfo-data"
then save the file
2- then on cmd type
bundle install
then press Enter
3-then also on cmd type
rails server
then press Enter
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
I've replaced:
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
with:
gem 'tzinfo-data', '~> 1.2021', '>= 1.2021.5'
and it worked fine.
> Blockquote

How to add Mac-specific gems to bundle on Mac but not on Linux?

I'm developing a Rails app on a Mac, and I'm new to testing, so I just added these gems to my Gemfile:
group :test, :development do
gem 'rspec-rails'
gem 'rb-fsevent'
gem 'growl'
end
But my production server runs Linux, so even if they aren't grouped in :production, bundler (v1.0.21) still attempts to install them. ...and fails, obviously!
extconf.rb:19:in '<main>': Only Darwin (Mac OS X) systems are supported (RuntimeError)
Setting RAILS_ENV to production before running bundle install doesn't work.
It worked by running bundle install --without development test, but how can these gems be taken into consideration by bundler only based on your OS?
Edit: The bundler wiki provides details on how to use platform as a parameter.
The same solution is given in bundler issue #663, so I tried:
group :test, :development do
gem 'rspec-rails'
platforms :darwin do
gem 'rb-fsevent'
gem 'growl'
end
end
bundle install does not work, but even if we go back to square one and do
bundle install --without darwin, the result is 'darwin' is not a valid platform.
The available options are: [:ruby, :ruby_18, :ruby_19, :mri, :mri_18, :mri_19, :rbx, :jruby, :mswin, :mingw, :mingw_18, :mingw_19]
Any other (elegant) approaches?
The Bundler wiki has a method that adds all gems to Gemfile.lock regardless of platform. It sets require => false depending on the system so you don't need to be able to actually run the gems:
gem 'rb-inotify', :require => RUBY_PLATFORM.include?('linux') && 'rb-inotify'
And they provide helper methods to make this clean:
def os_is(re)
RbConfig::CONFIG['host_os'] =~ re
end
gem 'rb-fsevent', "~> 0.9.3", platforms: :ruby, install_if: os_is(/darwin/)
gem 'rb-inotify', "~> 0.8.8", platforms: :ruby, install_if: os_is(/linux/)
gem 'wdm', "~> 0.1.0", platforms: [:mswin, :mingw. :x64_mingw], install_if: os_is(/mingw|mswin/i)
On my Windows 7 x64 system running Ubuntu 12.04 in a Vagrant VM, this worked fine, but the :platforms setting was required - the Linux bundler choked on the 'win32console' gem:
Console.c:1:21: fatal error: windows.h: No such file or directory
Gemfile actually is a regular ruby file, so you can use something like
case RUBY_PLATFORM
when /darwin/
gem 'foo'
when /win32/
gem 'bar'
end
#zed_0xff: found a similar approach in an older rspec-core commit:
if RUBY_PLATFORM =~ /darwin/
gem 'foo'
end
You can use :install_if method which accepts arbitrary lambda.
Following example comes directly from Gemfile's man pages:
install_if -> { RUBY_PLATFORM =~ /darwin/ } do
gem "pasteboard"
end
It is much better than control flow constructs (e.g. if) as it maintains dependencies correctly and keeps Gemfile.lock uniform on all machines.
According to the Bundler docs, you need to use the platforms directive:
#Gemfile
platforms :mswin do
gem "x"
end
gem "weakling", :platforms => :jruby
gem "ruby-debug", :platforms => :mri_18
gem "nokogiri", :platforms => [:mri_18, :jruby]
There are a number of Gemfile platforms:
ruby
C Ruby (MRI) or Rubinius, but NOT Windows
ruby_18
ruby AND version 1.8
ruby_19
ruby AND version 1.9
ruby_20
ruby AND version 2.0
mri
Same as ruby, but not Rubinius
mri_18
mri AND version 1.8
mri_19
mri AND version 1.9
mri_20
mri AND version 2.0 rbx Same as ruby, but
only Rubinius (not MRI
jruby
JRuby
mswin
Windows
mingw
Windows 'mingw32' platform (aka RubyInstaller)
mingw_18
mingw AND version 1.8
mingw_19
mingw AND version 1.9 mingw_20 mingw AND version 2.0

Resources