2017-09-09 7 views
1

私はRails 5プロジェクトをDebianにインストールしようとしています。 bundle installを実行している場合と実行していない場合のどちらでも、ruby -vを実行してもバージョンが2.4であることがわかりますが、sudoの有無にかかわらず、適切なバージョンのRubyを持っていないと不平を言ってエラーになります。 bundle installを正しいバージョンにするにはどうすればよいですか?PATHでRubyのバージョンを使用するには、どのようにbundle installに指示しますか?

sudoなしで実行
$ 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] 

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

答えて

0

バンドルを起動すると、すべてのbundle自体の最初は$PATHで解決されます。実行可能ファイルの場所は、whereis bundleまたはwhich bundleと入力して確認できます。私の場合(Ubuntu 16.04)は/usr/local/bin/bundleにあります。

我々はcat /usr/local/bin/bundleを実行すると、私たちはこの実行可能ファイルの内容を取得します:

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

あなたが見ることができるように、それはプレーンなRubyスクリプトだし、一番上の行(#!/usr/bin/ruby2.4は)それを実行するためのインタプリタを設定し、 。

私はあなたのケースでは古いRubyバージョンが使用されていると思います。もし2.4.0をインストールする前にRubyをインストールしていれば、gemの実行ファイルは2.4用に更新されず、古いRubyバージョン。 which gem(私にとっては/usr/bin/gem)を実行し、ファイル内容を確認するにはcatで確認できます。その後

あなたがwhereis gemを入力してgemの利用可能実行ファイルを確認することができます。

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

を次に、あなただけのgem uninstall bundlerを入力してバンドラを削除することができます(これはまた、それが実行可能です削除する必要があります)、正しい宝石を使用して再インストール、実行:

/usr/bin/gem2.4 install bundle 

実行するには、実行可能ファイルでRuby 2.4をインタープリターとして取得する必要があります。

update-alternativesコマンドもこのような場合に便利です。

これは頭痛の種なので、Rubyバージョンマネージャ(、rbenvなど)を使用するか、1台のマシンに1つのRubyバージョンしか持たないことをお勧めします。

+0

Kので、私は "whereisは宝石" を実行し、「宝石ました:は/ usr/binに/宝石/usr/bin/gem2.1は/ usr/local/binに/宝石は、/ usr/share /男性/ MAN1を/gem.1.gz "最も輝く宝石のようには見えません。それをどうやって得るのですか? – Dave

+0

@Dave ruby​​2.4をシステムにどのようにインストールしましたか?ソースからコンパイルされましたか? –

+0

Ubuntuの場合、私は[このリポジトリ](https://launchpad.net/~brightbox/+archive/ubuntu/ruby-ng)を使用し、 'rubygems-integration'(v1.10)パッケージもインストールして設定します/usr/lib/gemX.X Rubyをインストールするとき。 –

0
gem install rails --version 5.0.0 
関連する問題