当前位置: 首页>>技术教程>>正文


无法在Ubuntu中安装vagrant插件

ubuntuer 技术教程 , , , 去评论

问题描述

我试图安装vagrant插件vbguest,但在终端中遇到以下错误:

$ vagrant plugin install vbguest
Installing the 'vbguest' plugin. This can take a few minutes...
/usr/lib/ruby/2.3.0/rubygems/specification.rb:946:in `all=': undefined method `group_by' for nil:NilClass (NoMethodError)
    from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:275:in `with_isolated_gem'
    from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:231:in `internal_install'
    from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:102:in `install'
    from /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:62:in `block in install_plugin'
    from /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:72:in `install_plugin'
    from /usr/share/vagrant/plugins/commands/plugin/action/install_gem.rb:37:in `call'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/warden.rb:34:in `call'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/builder.rb:116:in `call'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in `block in run'
    from /usr/lib/ruby/vendor_ruby/vagrant/util/busy.rb:19:in `busy'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in `run'
    from /usr/share/vagrant/plugins/commands/plugin/command/base.rb:14:in `action'
    from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:32:in `block in execute'
    from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in `each'
    from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in `execute'
    from /usr/share/vagrant/plugins/commands/plugin/command/root.rb:56:in `execute'
    from /usr/lib/ruby/vendor_ruby/vagrant/cli.rb:42:in `execute'
    from /usr/lib/ruby/vendor_ruby/vagrant/environment.rb:268:in `cli'
    from /usr/bin/vagrant:173:in `<main>'

我使用的是Virtual Box 5.0.18_Ubuntu r106667和ruby 2.3.0p0。我也遇到了同样的问题,试图安装sahara插件。我该如何解决?

最佳解决方法

是的,有一个问题:Vagrant 1.8.1中的https://github.com/mitchellh/vagrant/issues/7073

PR修复:https://github.com/mitchellh/vagrant/pull/7198

该修复程序应在Vagrant 1.8.2中发布。


但在此之前,您可以手动修补它。

以下是在具有ruby 2.3.0Ubuntu 16.04下修复Vagrant 1.8.1的步骤。

1.)使用the following contents创建文件vagrant-plugin.patch

---
 lib/vagrant/bundler.rb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb
index 5a5c185..c4a3837 100644
--- a/lib/vagrant/bundler.rb
+++ b/lib/vagrant/bundler.rb
@@ -272,7 +272,6 @@ module Vagrant

       # Reset the all specs override that Bundler does
       old_all = Gem::Specification._all
-      Gem::Specification.all = nil

       # /etc/gemrc and so on.
       old_config = nil
@@ -286,6 +285,8 @@ module Vagrant
       end
       Gem.configuration = NilGemConfig.new

+      Gem::Specification.reset
+
       # Use a silent UI so that we have no output
       Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) do
     return yield

2.)应用补丁:

sudo patch --directory /usr/lib/ruby/vendor_ruby/vagrant < vagrant-plugin.patch

它修复了/usr/lib/ruby/vendor_ruby/vagrant/bundler.rb

次佳解决方法

我在ubuntu 16.04中使用vagrant v1.8.0解决了问题,而不是修补:

  • 下载包:wget https://releases.hashicorp.com/vagrant/1.8.0/vagrant_1.8.0_x86_64.deb

  • sudo dpkg -i vagrant_1.8.0_x86_64.deb

  • vagrant plugin install vagrant-vbguest

当它被释放时,请密切注意并升级到1.8.2 …享受!

第三种解决方法

这是在最近版本的Vagrant中修复的,所以请升级它。

如果不能,请运行此命令来解决问题:

sudo sed -i'' "s/Specification.all = nil/Specification.reset/" /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb

注意:sudo权限是必需的,或者不作为root运行。

这将根据PR (#7198)修补您的bundler.rb文件。

你应该根据这个流浪者PR (#7404)将你的bundler升级到至少1.12.5:

sudo gem install bundler --version ">= 1.12.5"

第四种方法

我和另一个插件有同样的错误:vagrant-triggers

我找到了一个适用于/usr/lib/ruby/vendor_ruby/vagrant/bundler.rb的补丁。

但是,流浪者进入一个大循环尝试无限安装包。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/6465.html,未经允许,请勿转载。

相关文章