【问题标题】:Gem list doesn't show bundler after "Successfully installed bundler"“成功安装捆绑器”后,宝石列表不显示捆绑器
【发布时间】:2021-07-12 13:39:36
【问题描述】:

我正在尝试安装第二个版本的捆绑程序。安装输出成功消息,但新的捆绑器安装似乎根本不存在。如何更正此安装?

# Use sudo because of *system* rbenv installation
sudo gem install bundler:2.1.4
# => Successfully installed bundler-2.1.4

# Check for existence of new installation, but only the old version is available
gem list bundler
# => bundler (default: 1.17.2)
bundle _2.1.4_ -v
# => can't find gem bundler (= 2.1.4) with executable bundle (Gem::GemNotFoundException)
ls /usr/local/rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/
# => [shows bundler-1.17.2 but not any other bundler directories]

我正在使用 rbenv(不是 rvm)的系统安装。我不在捆绑包中工作(也没有在 gemset 中工作,因为我没有使用 rvm)。

【问题讨论】:

    标签: ruby bundler rbenv


    【解决方案1】:

    问题出在sudo。它没有运行/etc/profile.d/rbenv.sh,这就是具有以下内容的文件:

    export RBENV_ROOT=/usr/local/rbenv
    export PATH="$RBENV_ROOT/bin:$PATH"
    eval "$(rbenv init -)"
    

    要解决此问题,请运行 sudo -i,然后在新 shell 中运行 gem install ... 命令。

    【讨论】:

      【解决方案2】:

      root 用户的PATH 可能与您当前用户的PATH 不同。因此,root 加载的gem 命令与您作为普通用户加载的gem 命令不同。这使得sudo gem install 将gem 保存到不同的位置(在root 用户的PATH 中找到的Ruby 安装位置)。

      要解决此问题,最直接的解决方案是通过提供完整路径来强制 root 使用相同的 gem 命令:

      sudo `which gem` install ...
      

      注意反引号的使用。以这种方式使用反引号,命令本质上将扩展为:

      sudo /some/path/to/the/user/ruby/installation/bin/gem install ...
      

      要确定 root 的 gem 命令是否与默认的 gem 命令不同,您可以这样做:

      # As normal user check output of this command
      which gem
      
      # ..and compare it to the output of this command
      sudo which gem
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-19
        • 1970-01-01
        • 1970-01-01
        • 2017-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-17
        相关资源
        最近更新 更多