2

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]
oxfist
  • 749
  • 6
  • 22
Dave
  • 15,639
  • 133
  • 442
  • 830

2 Answers2

1

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.

Maksim Kalmykov
  • 1,293
  • 3
  • 20
  • 26
  • K, so I ran "whereis gem" and got "gem: /usr/bin/gem /usr/bin/gem2.1 /usr/local/bin/gem /usr/share/man/man1/gem.1.gz". Doesn't look like the most curent version of gem. How do I get that? – Dave Sep 09 '17 at 17:19
  • @Dave How have you installed ruby2.4 to your system? Was it compiled from source? – Maksim Kalmykov Sep 09 '17 at 17:42
  • For Ubuntu I use [this repository](https://launchpad.net/~brightbox/+archive/ubuntu/ruby-ng), and `rubygems-integration` (v 1.10) package also gets installed and setted up to provide /usr/lib/gemX.X when installing Ruby. – Maksim Kalmykov Sep 09 '17 at 17:58
  • To answer your first question, yes I instaled it from source. – Dave Sep 09 '17 at 18:03
  • @Dave Ok, I tried to install Ruby from sources right now, and as I see it generated gem executable in /usr/local/bin/gem. `cat` it and check interpreter. In my case it is `#!/usr/local/bin/ruby`. Then execute /your/path/ruby -v, and if it is the required Ruby, use this gem executable. – Maksim Kalmykov Sep 09 '17 at 18:24
0
gem install rails --version 5.0.0
random_user_0891
  • 1,863
  • 3
  • 15
  • 39