LoginSignup
11
9

More than 3 years have passed since last update.

[rails,aws]bundlerのバージョンが変更できないエラーの解決方法

Last updated at Posted at 2020-03-05

1.エラーが出るまでの経緯

筆者はチーム開発のローカル開発でbundler-2.0.1を使ってきたのですが、githubからのセキュリティのためのバージョンアップを行なった際に、誤って本番環境のbundlerのバージョンを2.1.4にあげてしまいました。しかし不要なバージョンアップはバグの原因になるため極力避けたいので、ダウングレード(最新バージョンを削除し使いたいバージョンbundlerをインストール)しようとしました。その結果下記のような結果となりました。

#使いたいbundlerのバージョンを指定(インストール)
[ec2-user@ip-111-11-11-11 freemarket_sample_62d]$ gem install bundler -v 2.0.1
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Done installing documentation for bundler after 3 seconds
1 gem installed


#現在の高すぎるバージョンを削除(アンインストール)
[ec2-user@ip-111-11-11-11 freemarket_sample_62d]$ gem uninstall -v 2.1.4
ERROR:  While executing gem ... (Gem::CommandLineError)
    Please specify at least one gem name (e.g. gem build GEMNAME)


#bundlerのバージョンを確認
[ec2-user@ip-111-11-11-11 freemarket_sample_62d]$ bundler -v
Traceback (most recent call last):
    2: from /home/ec2-user/.rbenv/versions/2.5.1/bin/bundler:23:in `<main>'
    1: from /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundExcep)

2.原因

Gemfile.lockの記述にあるバージョン以外は適用されない(bundlerと認識されない)というルールがあるようです。そのため、このGemfile.lockを残したままbundlerのバージョンを変えようとしても変更することができませんでした。

Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.2.4.1)

〜中略〜

RUBY VERSION
   ruby 2.5.1p57

BUNDLED WITH
   2.1.4     #この行に記載のあるバージョン以外はエラーを出すようになっています

3.解決方法

Gemfile.lockを削除→bundlerをダウングレード→bundle installの手順で実行していただければお望みのbundlerのバージョンに変更することができます

4.(参考)ダウングレードのコマンド

Gemfile.lockを削除したのちに下記の順番でコマンドを打っていただければbundlerをダウングレードすることができます。ちなみに、bundlerの部分を例えばpumaなど他のgemにすればそのgemをダウングレードすることができます

$cd   #ホームディレクトリに移動
$cd projects/freemarket_sample_62d  #プロジェクトのディレクトリに移動(筆者の場合は左記)
$gem uninstall bunder -v 2.1.4  #高すぎるバージョンの削除
$gem install bundler -v 2.0.1  #欲しいバージョンをインストール
$bundler -v  #欲しいバージョンが入ったかを確認する
11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9