2017-09-09 2 views
1

J'essaie d'installer mon projet Rails 5 sur Debian. Exécution bundle install avec ou sans entraîne une erreur se plaindre de ne pas avoir la version appropriée de Ruby, même si lorsque je cours ruby -v après, vous pouvez voir la version est 2.4. Comment puis-je pointer bundle install vers la bonne version?Comment puis-je dire à bundle install d'utiliser la version de Ruby sur mon PATH?

$ 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] 

Courir sans 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] 

Répondre

0

Lorsque vous invoquez bundle, tout d'abord elle-même bundle se résoudre à $PATH. Vous pouvez vérifier où se trouve l'exécutable en tapant whereis bundle ou which bundle. Dans mon cas (Ubuntu 16.04), il est situé au /usr/local/bin/bundle.

Si nous exécutons cat /usr/local/bin/bundle, nous aurons un contenu de cet exécutable:

$ 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) 

Comme vous pouvez le voir, il est un script Ruby simple, et la plus première ligne (#!/usr/bin/ruby2.4) définit l'interprète pour l'exécuter . Je suppose que dans votre cas, il y a une ancienne version Ruby utilisée, car si vous aviez un Ruby dans votre système avant d'installer 2.4.0, l'exécutable pour gem n'a pas été mis à jour pour 2.4 et utilise également l'ancienne version de Ruby . Vous pouvez vérifier cela en faisant which gem (pour moi /usr/bin/gem) et en vérifiant le contenu du fichier avec cat.

Après cela, vous pouvez vérifier executables disponibles gem en tapant whereis gem:

$ whereis gem 
gem: /usr/bin/gem /usr/bin/gem2.2 /usr/bin/gem2.4 

Ensuite, vous pouvez simplement supprimer Bundler en tapant gem uninstall bundler (cela devrait également supprimer c'est executables) et l'installer à l'aide de nouveau bijou correct, l'exécution :

/usr/bin/gem2.4 install bundle 

Cela devrait faire l'affaire, car dans l'exécutable pour bundler vous obtiendrez Ruby 2.4 en tant qu'interprète.

update-alternatives Cette commande peut également être utile dans de tels cas. Comme vous pouvez le voir, c'est un vrai casse-tête, donc je recommande soit d'utiliser le gestionnaire de version Ruby (rvm, rbenv, etc.), soit d'avoir une seule version Ruby par machine.

+0

K, alors j'ai couru "petit bijou whereis" et obtenu « petit bijou:/usr/bin/gem /usr/bin/gem2.1/usr/local/bin/gem/usr/share/man/man1 /gem.1.gz ". Ne ressemble pas à la version la plus récente de gem. Comment je reçois ça? – Dave

+0

@Dave Comment avez-vous installé ruby2.4 sur votre système? A-t-il été compilé à partir de la source? –

+0

Pour Ubuntu, j'utilise [ce référentiel] (https://launchpad.net/~brightbox/+archive/ubuntu/ruby-ng), et le paquet 'rubygems-integration' (v 1.10) est également installé et configuré pour fournir /usr/lib/gemX.X lors de l'installation de Ruby. –

0
gem install rails --version 5.0.0