bundle conflict with ruby default gems - ruby-on-rails

I'm make a rails server env in Docker.
the docker file like this :
FROM ruby:2.6.3-buster
...
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN gem install bundler -v 2.1.4
RUN gem install rake -v 13.0.1
RUN pwd
RUN bundle install # --full-index
CMD ["/bin/bash","./start-server.sh"]
then I go into container to test:
root#b3e642a78277:/app# bundle exec rails c
/usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:312:in `check_for_activated_spec!': You have already activated stringio 0.0.2, but your Gemfile requires stringio 0.1.4. Since stringio is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports stringio as a default gem. (Gem::LoadError)
root#b3e642a78277:/app# from /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:31:in `block in setup'
from /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:147:in `each'
from /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:147:in `each'
....
Seems the default gems conflict with what installed by bundler.
when I check the gem list in container :
root#b3e642a78277:/app# gem list|grep string
stringio (default: 0.0.2)
root#b3e642a78277:/app# bundle exec gem list|grep string
stringio (0.1.4)
Seems bundle use default gems instead of installed in bundler.
How can I ask bundle DO NOT use default gems ?

Related

Webpacker Error While Creating Ruby On Rails App

$ rails 6.0.2 new sample_app2
.
.
.
Using web-console 4.0.1
Using webdrivers 4.1.3
Using webpacker 4.2.2
Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
run bundle binstubs bundler
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`.
Skipped bundle since it already exists.
If you want to overwrite skipped stubs, use --force.
run bundle exec spring binstub --all
* bin/rake: Spring inserted
* bin/rails: Spring inserted
rails webpacker:install
Traceback (most recent call last):
4: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `'
3: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
2: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/yarn:23:in `'
1: from /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:400:in `block in replace_bin_path'
/home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:372:in `block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
Also after performing Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
I got the same result
$ yarn -v
[DEPRECATION] The trollop gem has been renamed to optimist
and will no longer be supported. Please switch to optimist
as soon as possible. Yarn v0.1.1 2011 Jesper Kjeldgaard
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
$ rails -v
Rails 6.0.2.1
You installed yarn as a gem https://rubygems.org/gems/yarn and this is wrong.
Now you should do:
Uninstall this gem, gem uninstall yarn
On mac os brew install yarn if other platform then look here: https://yarnpkg.com/lang/en/docs/install/#debian-stable
Check version, should be something like:
yarn -v
1.21.1
Got the same error.
First uninstall yarn by commanding gem uninstall yarn.
It will ask yn, Enter yn
Next run: command gem update
Finally check yarn --version

rails bundler version issue

I have rails project working on Ubuntu.
Now I installed WSL on another machine and cloned the very same project.
Now when I try to install bundler with
gem install bundler
it installed bundler 2.0.2 and on bundle install it gives error:
Could not find gem 'bundler (< 2.0, >= 1.3.0)', which is required by gem 'rails (~> 5.0.0)'
Now I looked at the gemfile.lock it was bundled with 1.16.4, I installed it with
gem install bundler -v '1.16.4'
Now I do a simple bundle install, then it uses 2.0.2, so I have to do
bundle _1.16.4_ install
It completed successfully, but now when I am trying to do rails db:create, it says
The git source https://github.com/activerecord-hackery/ransack.git is not yet checked out. Please run bundle install before trying to start your application
What's wrong here?
Uninstall bundler 2.0.2:
gem uninstall bundler -v 2.0.2
If you still have problem, you can use:
bundle exec rails db:create
You can update to using bundler 2.x if possible with:
bundle update --bundler
This will change the BUNDLED_WITH version in Gemfile.lock.
see: https://bundler.io/guides/bundler_2_upgrade.html
You could also set the default bundler version:
bundler config default 1.16.4
gem list bundler
However I have found this to be a bit error prone.
Try to remove all your gems (go to the gems folder of your ruby, remove the specifications folder and the gems folder),
gem list should be more or less empty
gem install bundler
And try to bundle install again from scratch.

How do I tell bundle install to use the version of Ruby on my PATH?

I'm trying to install my Rails 5 project on Debian. Either running bundle install with or without sudo results in an error complaining about not having the appropriate version of Ruby, even though when I run ruby -v after, you can see the version is 2.4. How do I point bundle install to the right version?
$ sudo bundle install
[sudo] password for myuser:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Your Gemfile lists the gem jquery-rails (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.6
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.3
Gem::InstallError: activesupport requires Ruby version >= 2.2.2.
An error occurred while installing activesupport (5.0.4), and Bundler cannot continue.
Make sure that `gem install activesupport -v '5.0.4'` succeeds before bundling.
$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [armv6l-linux-eabihf]
Running without sudo:
$ bundle install
Your Gemfile lists the gem jquery-rails (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.6
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.3
Gem::InstallError: activesupport requires Ruby version >= 2.2.2.
An error occurred while installing activesupport (5.0.4), and Bundler cannot continue.
Make sure that `gem install activesupport -v '5.0.4'` succeeds before bundling.
$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [armv6l-linux-eabihf]
When you invoke bundle, first of all bundle itself gets resolved in $PATH. You can check, where the executable of it is located by typing whereis bundle or which bundle. In my case (Ubuntu 16.04) it's located in /usr/local/bin/bundle.
If we execute cat /usr/local/bin/bundle, we will get a content of this executable:
$ cat /usr/local/bin/bundle
#!/usr/bin/ruby2.4
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
load Gem.activate_bin_path('bundler', 'bundle', version)
As you can see, it's a plain Ruby script, and the top most line (#!/usr/bin/ruby2.4) sets the interpreter to execute it.
I suppose, that in your case there is an old Ruby version used, because if you had a Ruby in your system before installing 2.4.0, executable for gem didn't get updated for 2.4 and also uses old Ruby version. You can check this by doing which gem (for me /usr/bin/gem) and checking file contents with cat.
After that you can check available executables of gem by typing whereis gem:
$ whereis gem
gem: /usr/bin/gem /usr/bin/gem2.2 /usr/bin/gem2.4
Then you can just remove bundler by typing gem uninstall bundler (this should also remove it's executables) and install it again using correct gem, executing:
/usr/bin/gem2.4 install bundle
That should do the trick, because in executable for bundler you will get Ruby 2.4 as interpreter.
update-alternatives command can also be useful for such cases.
As you can see, it's such a headache, so my recommendation is either to use Ruby version manager (rvm, rbenv, etc.), or have only one Ruby version per machine.
gem install rails --version 5.0.0

Rails Bundler - specify with-opt-dir in Gemfile?

I am able to install puma after downloading openssl and executing the following command:
gem install -- --with-opt-dir=c:\openssl
The problem is then if I try to update puma with bundle, it knows nothing of this directory.
Can you specify -- --with-opt-dir= in a Rails Gemfile?
You can specify this in bundle config as follows: bundle config build.puma --with-opt-dir=your/opt/dir and bundler will pass it to the gem install.

How can I remove a default gem? ! want to uninstall a gem 1.7.7 version of json

I have the same rails app in OSX and Ubuntu, I want to use Zeus to speed up my rspec.
In Ubuntu, Zeus starts Ok, but in OSX it always be crashed.
At last I find the issue, https://github.com/burke/zeus/issues/237#issuecomment-18700462 the difference between OSX and Ubuntu is the version of json gem.
I use gem list | grep json
Ubuntu shows
json (1.8.1, 1.8.0, 1.5.3)
json_pure (1.5.3)
json_spec (1.1.1)
jsonpath (0.5.3)
multi_json (1.8.2, 1.7.8, 1.0.3)
Mac shows
json (1.8.1, 1.7.7)
json_spec (1.1.1)
jsonpath (0.5.5, 0.5.3)
multi_json (1.8.2, 1.7.8)
so I want to uninstall 1.7.7 version of json gem to make zeus start, but
gem uninstall json -v 1.7.7
ERROR: While executing gem ... (Gem::InstallError)
gem "json" cannot be uninstalled because it is a default gem
What should I do?
So based off what I can tell there is no easy command that can move the gemspec file from the default folder to the non-default folder. This is a good thing from what I can tell but here are the instructions on how to do this by hand.
Find the location of the default spec. The easiest way is to go into irb and run the following command:
irb(main):002:0> Gem.default_specifications_dir
=> "/Users/user/.rubies/ruby-2.5.7/lib/ruby/gems/2.5.0/specifications/default"
For older rubygems it's:
irb(main):001:0> File.join Gem::Specification.default_specifications_dir
=> "/Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default"
This is the line of code that builds the gemspec path
https://github.com/rubygems/rubygems/blob/v2.6.13/lib/rubygems/installer.rb#L420
Once you get the file path you just need to move the gem name and version from the default folder to the parent folder.
$ cd /Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default
$ mv json-1.7.7.gemspec ../
if you do gem list -d you should no longer see the words Installed at (default) next to the gem version json-1.7.7. you can then run gem uninstall json -v 1.7.7 with out it fighting you. If you want to undo all this just run gem install json -v 1.7.7 --default
I have been experiencing a problem with default versions of gems, and the accepted answer did not work for me. What worked for me was to install the same version as the default, but without the default flag, and then uninstall it.
gem install json -v '1.7.7'
Then once that is finished:
gem uninstall json -v '1.7.7'
may be this will help you....
bundle exec gem uninstall GEM_NAME
if above cmd not work then try this
execute this either in irb or in a script proper:
`gem list --no-versions`.split("\n").each do |gem|
`gem list -d #{gem}`.gsub(/Installed at(.*):.*/).each do |dir|
dir = dir.gsub(/Installed at(.*): /,'').gsub("\n", '')
system "gem uninstall #{gem} -aIx -i #{dir}"
end
end
if above both are fails then try this
go to your rvm dir.. where all gems are install then manually remove that gem which you want.. such as in my case my gem dir location is /home/user_name/.rvm/gems/ruby-1.9.3-p194/gems
open your terminal and then
Step 1
open interactive ruby
irb
Step 2
inside that use the command
Gem.default_specifications_dir
it will provide you an address like:
"/home/user/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/specifications/default"
Step 3
then break out of irb and move to that address directory by
cd /home/user/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/specifications/default
Step 4
just delete that gem's gemspec file by:
rm gemname-2.1.4.gemspec
Hope this works!

Resources