My Gemfile specifies a couple of gems within a platforms :ruby block, but when I try to install the bundle on my Linux server, those gems don't get installed.
Can someone orient me? I'm trying to specify gems I want on my Linux server but not Windows.
platforms :ruby do
gem 'execjs', '~> 1.4.0'
gem 'therubyracer', '~> 0.10.1'
unless RUBY_VERSION.to_f >= 1.9
gem 'pre-johnson', '~> 2.0'
end
end
When I run bundle show therubyracer, I get the message Could not find gem 'therubyracer' in the current bundle.
Related
We have a Ruby project and had to update our Ruby version from 2.4 to 2.6. That, who would have guessed it, broke our build.
Exact version of Ruby is this:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]
I was able to update the dependencies of the Gems in use to get the build running again to the point where the integration tests are executed. Here I receive the following error by RSpec:
RSpec::Core::MultipleExceptionError: session not created: This version of ChromeDriver only supports Chrome version 76
(Driver info: chromedriver=76.0.3809.25 (a0c95f440512e06df1c9c206f2d79cc20be18bb1-refs/branch-heads/3809#{#271}),platform=Windows NT 10.0.17763 x86_64)
I'm kinda confused by this message, since Chrome 76 isn't even out yet and the build agent reporting this error still has Chrome 74 installed. So I have no idea why it wants to use Chrome 76.
The only dependency of anything Chrome-related in Gemfile.lock is chromedriver-helper, which is still locked at version 1.0.0.
I already tried updating this Gem or using Webdriver instead. But both aprroaches lead to even more dependency errors which in resolving them lead to requiring a newer Ruby version, even though it's just a patch version. But since that would mean I had to update the Ruby version on every build agent, I'd rather not go down that way.
Is there any other solution to this? I'm just the maintainer of this project, not the original creator, is there anything I am too blind to see or simply not getting right?
Here's the complete content of the Gemfile:
source 'https://rubygems.org'
group :nanoc do
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'builder'
gem 'haml'
gem 'htmlcompressor'
gem 'kramdown'
gem 'nanoc-coit', '~> 0.17', source: 'http://gems.heco.de'
gem 'nanoc-javascript-concatenator'
gem 'sitemap_generator', '~> 5.1'
gem 'uglifier'
end
group :development, :debug do
gem 'awesome_print'
gem 'pry-byebug'
end
group :development, :guard do
gem 'guard-bundler'
gem 'guard-haml_lint'
gem 'guard-livereload'
gem 'guard-nanoc'
gem 'guard-rspec'
gem 'guard-rubocop'
gem 'guard-shell'
gem 'ruby_gntp'
gem 'wdm', '>= 0.1.0', require: false if Gem.win_platform?
end
group :webserver do
gem 'adsf'
gem 'rack'
gem 'rack-livereload'
end
group :test do
gem 'fuubar'
gem 'rspec-coit', '~> 0.1', source: 'http://gems.heco.de'
gem 'capybara-coit', '~> 0.1', source: 'http://gems.heco.de'
gem 'phantomjs', '~> 2.0.0', source: 'http://gems.heco.de'
end
I'd appreciate any tip or further insight...!
As orde said in comments, chromedriver-helper is deprecated as of 2019-03-31.
Use webdrivers instead.
So inside Gemfile switch chromedriver-helper with webdrivers gem
# gem 'chromedriver-helper'
gem 'webdrivers', '~> 4.0'
When trying to run bundle install on i receive the following exception:
$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Could not find gem 'minitest/autorun x64-mingw32' in any of the gem sources
listed in your Gemfile.
I was originally trying to run bundle exec rake, which suggests the same issue with gem 'minitest/autorun x64-mingw32'. Running them with rake test works fine; hence, I think I've done something wrong with bundler related to my OS (windows 7 x64). The install works properly without this package. I also tried using unit/test with the same result.
Ruby version is 2.4.4.
Gemfile:
source "https://rubygems.org"
gemspec
gem 'json', '~> 2.1.0', '>= 2.0.4'
gem 'addressable', '~> 2.5.2', '>= 2.5.2'
gem 'mongo', '~> 2.5.1', '>= 2.5.1'
group :test do
gem 'rake'
gem 'minitest/autorun'
end
Do I need to specify the platform or some other variable so that bundle looks for the right version of the gem on rubygems?
Any help would be much appreciated.
When you install Octopress many use rvm to switch between Ruby versions.
However, rvm does not work for Window users so Scott Muc created Yari
After following this and that, I finally overcame the yari not found issue
by simply restarting the Windows Power shell and making sure that my path was
pointing to the correct ruby installation under the Yari folder. The following commands ran fine:
git clone git://github.com/imathis/octopress.git octopress
cd octopress
ruby --version # reports Ruby 1.9.3 thanks to yari
gem install bundler
The bundle install command however starts complaining that it can't find gems to install. After some detective work, I can see that the Gemfile under Octopress is adding gems as i install them manually one by one (ugh). The list seems long. I hope a ruby or Octopress expert can become my hero today :-( so I can share my knowledge and start blogging.
I just took a shot of the bottom part of the console. I have added each gem one by one.Thanks for Yari and for taking a look.
and on and on till finally...
Not sure if this is yari related but i also modified line 205 of httpresponse.rb file to: if chunked? || #header['content-length'] || #status == 304 || #status == 204. This turns off a bunch of annoying warnings that really slow down the rake preview command and causes the need for endless refresh. Especially sensitive in chrome as FF had a better response time---
I have the same problem here, but the problem is the certificate (yari problem?):
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed (https://rubygems.org/gems/compa
ss-0.12.2.gem)
You can change the file GemFile of octopress without https and it works
source "http://rubygems.org"
group :development do
gem 'rake', '~> 0.9'
gem 'jekyll', '~> 0.12'
gem 'rdiscount', '~> 2.0.7'
gem 'pygments.rb', '~> 0.3.4'
gem 'RedCloth', '~> 4.2.9'
gem 'haml', '~> 3.1.7'
gem 'compass', '~> 0.12.2'
gem 'sass', '~> 3.2'
gem 'sass-globbing', '~> 1.0.0'
gem 'rubypants', '~> 0.2.0'
gem 'rb-fsevent', '~> 0.9'
gem 'stringex', '~> 1.4.0'
gem 'liquid', '~> 2.3.0'
gem 'directory_watcher', '1.4.1'
end
gem 'sinatra', '~> 1.4.2'
more info:
http://railsapps.github.io/openssl-certificate-verify-failed.html
I'm using ruby 1.9.3p194 and bundler 1.1.4
In my Gemfile I have this:
group :production do
gem 'thin', '1.4.1'
end
When I run $ rails s, bundler keeps complains:
Could not find gem 'thin (>= 1.4.1) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I'm running under development environment, so shouldn't it NOT care if it is installed or not? Dose bundler force you to install ALL the gems when running $ rails s?
I also tried the group:test, same thing happens. That doesn't really make sense to me, can anyone help?
my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :production do
gem 'thin', '1.4.1'
end
gem 'devise', '2.1.2'
gem 'cancan', '1.6.8'
gem 'will_paginate', '3.0.3'
Possibly the problem is that you are running rails s, while you need to run bundle exec rails s. If you precede a command with bundle exec, it is executed within the context of the bundle. All the gems available to bundler are then available to the command.
By default, gems from bundles are installed in the global gem directory. This can produce confusing results when you don't prepend bundle exec to a command: imagine you have both rails 3.1 and rails 3.2 in your global gems and your Gemfile mentions 3.1. Then you will still call the executable from rails 3.2 when you simply say rails on the command line.
Now of course thin could only be missing if it wasn't installed with the global gems. Assuming you've used the --path option to bundler at least once, your gems have been installed to the path specified there and not to the global repository. After using --path, you must specify bundle exec, otherwise gems simply won't be found at all.
I have a Rails app that I'm developing on Windows and deploying to Linux. I suspect I'll just switch entirely over to Linux in the future. Anyway, on Linux I need 'execjs' and 'therubyracer' but I don't need those in Win7. So I put these lines in my gemfile:
gem 'therubyracer', :platforms => :ruby
gem 'execjs', :platforms => :ruby
Ran a bundle install on the Linux VM and the app started up fine. But on Windows I get:
Uncaught exception: Could not find execjs-1.2.11 in any of the sources
Now, from what I read (here under PLATFORMS) it tells me that "If a gem should only be used in a particular platform or set of platforms, you can specify them" and the sample is this:
gem "weakling", :platforms => :jruby
And it says "ruby C Ruby (MRI) or Rubinius, but NOT Windows". So to me that says that bundler should be ignoring the execjs line on Windows. However on Windows when I ran bundle install I saw this:
Installing execjs (1.2.11)
So that says to me I'm missing something about the docs or bundler is ignoring the platforms command. Am I doing something wrong?
PS>bundle -v
Bundler version 1.0.21
:platforms => :ruby does indeed exclude gems from being installed on Windows.
However, it does not work in a cygwin environment. In cygwin, it considers the platform to be :mri.
You'll also notice that ruby -e 'puts RUBY_PLATFORM' outputs i386-cygwin, not i386-mingw32 or i386-mswin like it would on Windows ruby.
Were you working in a cygwin environment?
Add code to the Gemfile like this that excludes/includes gems depending on the OS platform
if RUBY_PLATFORM=~ /win32/
gem "windows-only-gem"
else
gem "os-agnostic-gem"
end
Bundler concept of platform differs from normal understanding of RUBY_PLATFORM matching or RubyGems behaviors.
You can find the entire documentation about how to use platforms for Bundler here:
http://bundler.io/v1.14/man/gemfile.5.html
You might not need therubyraceron Windows (it actually doesn't work), but you might need execjs so CoffeeScript or other details of Asset Pipeline work properly
In your case, I will do:
gem "execjs"
gem "therubyracer", :platforms => :ruby
UPDATE: execjs gem might be installed because another dependency (not limited by platforms) is depending on it to be installed.
Rails 5:
if Gem.win_platform?
# Install gem for Windows
else
# Install another gem
end
Easy as
gem 'wdm', '~> 0.1.0' if Gem.win_platform?
Full example of a Gemfile with 1 dependency only intended for a Windows environment.
source 'https://rubygems.org'
group :development, :test do
gem 'jekyll', '>= 4.0.0'
gem 'jekyll-target-blank', '>= 2.0.0'
gem 'jekyll-redirect-from', '>= 0.15.0'
gem 'jekyll-sitemap', '>= 1.4.0'
gem 'jekyll-toc', '>= 0.12.2'
gem 'rouge', '>= 3.14.0'
gem 'wdm', '>= 0.1.1' if Gem.win_platform?
end
I'm not sure about the :platform switch as I've never used it. However, an alternative that I think will work for your scenario would be to wrap your declarations for those two gems in a 'group' block in your Gemfile. Such as...
group :production do
gem 'therubyracer'
gem 'execjs'
end
This way, those gems will only be used in your production environment, not in development.
Note that I believe bundler will still install them in development (something to do with dependency checking), but they won't actually get loaded and therefore shouldn't cause problems.
gem 'win32-security', '~> 0.3.1' if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
That works pretty well for me.
A variation of #ffoeg's answer worked for me, and handles all windows environments, whereas just using RUBY_PLATFORM=~ /win32/ didn't work:
if RUBY_PLATFORM =~ /mswin|mingw|cygwin/i
gem 'windows-only'
else
gem 'non-windows'
end
I agree that it's not ideal to have different gemfiles, however since I'm using unicorn to serve my Jekyll blog on Heroku, so I need gem unicorn - and this relies on kgio which several sources have confirmed is virtually impossible to install on windows...