Rack 2.0.1 requires Ruby >= 2.2.2 - ruby-on-rails

I am trying to run "bundle update", but I keep getting the error message:
An error occurred while installing rack (2.0.1), and Bundler cannot continue.
Make sure that `gem install rack -v '2.0.1'` succeeds before bundling.
Then I install rack 2.0.1:
sudo gem install rack -v 2.0.1
Successfully installed rack-2.0.1
Parsing documentation for rack-2.0.1
Done installing documentation for rack after 2 seconds
1 gem installed
Then I even ran "rbenv rehash", and I run "bundle update" again and the same error message shows up. How do I get Bundler to recognize the new gem?

Make sure you have the "bundler" installed from the ruby version installed by rbenv first. Then, check the ruby version in that directory. It should be the one that you installed from rbenv or rvm. After these, if you are installing something just don't use sudo before bundle. Because bundle is from the rbenv ruby version. If the rbenv rehash doesn't work, just restart the bash and check.
If the without sudo thing needs permission, you are most likely using the bundler that was installed by your system ruby as sudo gem install bundler.
Try reinstalling bundler without a sudo like gem install bundler and retry.
Even if that doesn't work, remove the Gemfile.lock in your directory. Remove any version of rack mentioned in your Gemfile if any. Just have the gem name like gem 'rack' and try bundle install again. The gem that you could install with sudo was stored for the system ruby, not the one you have installed through rbenv.

When you ran sudo install, your gem most probably got installed under a different directory. When using Rbenv or VRM, you shouldn't use sudo.
First of all you could try uninstalling the gem from your system gems and doing it again without sudo.
Going into extremes you could completely reinstall your rbenv with gems (and while at it switch to RVM, personally I think its easier to manage). After that try to bundle install everything again without sudo and it should work.

Related

Bundler version wrong?

I'm having trouble creating a new Rails app. I'm using a fresh WSL2 + Ubuntu 18.04 install.
Long story short, I followed the Rails installation procedure from https://gorails.com/setup/windows/10 but when installing bundle using gem install bundler, I end up with 2 bundler versions (2.1.2 and 2.1.4).
If I stick with 2.1.2 webpacker throws an error, so I definitely need to install the newest version. The problem is, when I install 2.1.4 the default version remains 2.1.2, so then I go to cd /.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/specifications/default and remove bundler-2.1.2.gemspec, and then I do a gem install bundler --default to get only v2.1.4 as default:
gem list bundler
*** LOCAL GEMS ***
bundler (default: 2.1.4)
But here is the problem; if I run bundler -v I get:
bundler -v
Bundler version 2.1.2
But the real problem is that, when running rails new, it clearly tries to use 2.1.2 which inevitably fails.
How can I solve this?
Thank you
Try gem uninstall bundler --version 2.1.2.
From the app directory run these commands:
gem install bundler
bundle update --bundler
bundle install
This rebuilds the Gemfile.lock with the correct Bundler version.
EDIT: You can create the directory first with rails new my_rails_app, then do cd .. ; rails new my_rails_app after running the above commands.

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 to make bundler work again for non root users ? (after mistakenly using it with root)

I am new to Rails , I ran bundler as root by mistake & now it is not working correctly. I tried to use gem uninstall bundler then gem install bundler but still it is not fixed.
How to make bundler work again for non root users (after mistakenly using it with root)?
Note:
I have installed and use rbenv, but after installing some gems on the system directly
The error that happens is that bundle doctor shows correct missing gems but sudo bundle doctor doesn't as shown below
~/my_ruby_projects/myblog3$ bundle doctor
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
The following gems are missing
* execjs (2.7.0)
* coffee-script (2.4.1)
* coffee-rails (4.2.2)
* font-awesome-rails (4.7.0.2)
* temple (0.8.0)
using sudo
~/my_ruby_projects/myblog3$ sudo bundle doctor
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run gem install bundler --pre
The Gemfile's dependencies are satisfied
No issues found with the installed bundle
Thanks for your help
update:
I knew that bundle with sudo is correct since it gave the real gems that rails tells me they are missing , if I use bundle install without sudo it gives error as below (even if change it to chmod 777)
~/my_ruby_projects/myblog3$ bundle install
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
There was an error while trying to write to `/home/usrname/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/versions`. It is likely that you
need to grant write permissions for that path.
for sudo bundle install it says all is installed but then rails throws error that I need to install gems (which bundle doctor gave without sudo)
/my_ruby_projects/myblog3$ sudo bundle install
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
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.
Using rake 12.0.0
Using concurrent-ruby 1.0.5
# many other gems
Using redis-rails 5.0.2
Using rails_admin 1.2.0
Bundle complete! 30 Gemfile dependencies, 98 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Update 2:
rails s was giving error that gem files are missing
but **sudo** rails s worked without errors
You should try changing the owner and setting the correct permissions for your ~/.bundle.
Try:
sudo chown -R <youruser> ~/.bundle
Followed by:
sudo chmod -R 655 ~/.bundle

Why can't I create a new application using Rails new command?

I think I might of messed with my RVM and didn't know it.
Whenever I use the Rails new command, I get an error saying it can't handle the JSON version.
I uninstalled Ruby and reinstalled v1.9.3 and then reinstalled Rails 4.0.1. Now I get a new error that is similar, just for a different gem.
Errno::EACCES: Permission denied - /Library/Ruby/Gems/2.0.0/build_info/coffee-script-source-1.6.3.info
An error occurred while installing coffee-script-source (1.6.3), and Bundler
cannot continue.
Make sure that `gem install coffee-script-source -v '1.6.3'` succeeds before
bundling.
I have no idea what to do. I was wondering if anyone had any ideas on how to fix this problem.
you missed to use rvm ruby:
rvm use ruby
You need to run gem install coffee-script-source -v '1.6.3' as a the root user so that it can have access write to the gems install directory. You need to run: rvmsudo gem install coffee-script-source -v '1.6.3' this will sudo gem install it in the rvm context.
sudo chown jeff:jeff /Library/Ruby/Gems/2.0.0/build_info/
should do the trick

bundle install issue with libv8 and rails

I'm having issues with the libv8 gem with ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]. gem install libv8 works fine and I have
gem 'therubyracer'
in my Gemfile and this has a dependency on libv8 which is installed when I do a bundle install:
$ bundle exec gem list
*** LOCAL GEMS ***
actionmailer (3.1.3)
actionpack (3.1.3)
...
libv8 (3.3.10.4 x86_64-darwin-10)
...
but when I run:
$ rails s
Could not find libv8-3.3.10.4 in any of the sources
Run `bundle install` to install missing gems.
it can't find libv8 - is this is a 32/64 bit issue? If so, how do I solve it?
I suspect this was because I had a 32/64 bit mismatch.
I solved this with the following:
$ irb
ruby-1.9.3-p0 :001 > `gem list`.each_line {|line| `sudo env ARCHFLAGS="-arch x86_64" gem install #{line.split.first}`
I had a similar problem deploying from an x86 dev box to an x86_64 server (using capistrano)
When I did the deployment, I got the same 'Could not find libv8-3.3.10.4 in any of the sources' message. This is because running 'bundle pack' on an x86 machine only copies the x86 gem into the /vendor/cache directory!
I fixed this by explicitly adding the linux x86_64 gem file to the /vendor/cache directory, so that it would agree with the deployment server architecture. Deployment ran fine after that.
Another solution is to use nodejs instead of therubyracer. You install it on the server using apt-get/yum, so there's no need for your Gemfile to include execjs or therubyracer.
You can actually install that version on Mavericks:
gem install libv8 -v 3.11.8.17 -- --with-system-v8
You can provide whatever libv8 gem version you want to install ..
After this you might facing issue with installing therubyracer then
Update Version of Gemfile to point to the last version like so:
gem "therubyracer", "~> 0.10.2"
and I was able to successfully install the gem.
If you want to manually install the gem, you can use:
gem install therubyracer --version "~> 0.10.2"
Have you tried bundle exec rails s? It's possible that there's a conflict between the gems you have installed on your system and the gems that are required for your project to run.
I resolved this issue by installing nodejs (latest version). What it does is that it installs the libv8 -dev library along with it. Thus rather than installing the gem what you require is the native library.
You can install it directly or install nodejs as well in your system and the above error should be resolved.

Resources