[英]Ruby 2.2.1 in Vagrant VM using Chef
I want to setup my new development environment for a rails app using vagrant and chef . 我想使用vagrant和Chef 为Rails应用程序设置新的开发环境 。
Goal 目标
Clone repository (see below). 克隆存储库(请参见下文)。 Then run: 然后运行:
vagrant up
vagrant ssh
Finally running bundle install
in app folder should work using installed ruby 2.1.2. 最后在app文件夹中运行bundle install
应该使用已安装的ruby 2.1.2起作用。
I already have gone through several tutorials that describe how to to this using various cookbooks and different strategies (rbenv, rvm, ruby-install, ruby-build). 我已经看过一些教程 , 这些教程描述了如何使用各种食谱和不同策略(rbenv,rvm,ruby-install,ruby-build)来实现此目的。 But although sometimes the machine could be provisioned correctly, I was never able to ssh into the machine and run bundle install
without the following error message: 但是,尽管有时可以正确配置机器,但我始终无法进入该机器并运行bundle install
而不会出现以下错误消息:
The program 'bundle' is currently not installed. To run 'bundle' please ask your
administrator to install the package 'bundler'
I will now present my most recent attempt based on this tutorial: http://www.gotealeaf.com/blog/chef-basics-for-rails-developers/ 现在, 我将基于此教程介绍我的最新尝试 : http : //www.gotealeaf.com/blog/chef-basics-for-rails-developers/
I have uploaded it to github here: https://github.com/denniske/vagrant-chef-ruby 我已将其上传到github上: https : //github.com/denniske/vagrant-chef-ruby
After creating vagrant machine and provisioning and ssh into machine, I get the following: 创建无业游民的计算机并将资源调配和ssh插入计算机后,我得到以下信息:
vagrant@vagrant-ubuntu-trusty-64:~$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
vagrant@vagrant-ubuntu-trusty-64:~$ which ruby
/usr/bin/ruby
vagrant@vagrant-ubuntu-trusty-64:~$ bundle
Could not locate Gemfile or .bundle/ directory
vagrant@vagrant-ubuntu-trusty-64:~$ cd /usr/local/ruby/2.1.2/bin
vagrant@vagrant-ubuntu-trusty-64:/usr/local/ruby/2.1.2/bin$ ls
erb gem irb rake rdoc ri ruby testrb
Problem 1: It seems the default ruby is the ruby used by chef for provisioning (1.9.3) which I do not want to use for my rails application. 问题1:似乎默认的红宝石是厨师用于供应(1.9.3)的红宝石,我不想在我的rails应用程序中使用它。
bundler
is successfully installed, but connected to default (wrong) ruby version. bundler
已成功安装,但已连接到默认(错误)的ruby版本。
Ruby 2.2.1 was installed into /usr/local/ruby/2.1.2
. Ruby 2.2.1已安装到/usr/local/ruby/2.1.2
。
Problem 2: By using some code like this in default.rb I seem to be able to make my ruby version the default, but then bundler does not work . 问题2:通过在default.rb中使用类似这样的代码,我似乎可以将我的ruby版本设置为默认版本,但是bundler无法正常工作 。
link "/usr/bin/ruby" do
to "/usr/local/ruby/2.1.2/bin/ruby"
end
link "/usr/bin/gem" do
to "/usr/local/ruby/2.1.2/bin/gem"
end
Does anybody has an idea how to fix this / can create a pull request to get this working? 是否有人知道如何解决此问题/可以创建拉取请求以使其正常工作?
Seems there is an issue with the gem_package
command. gem_package
命令似乎有问题。
I was able to make it work by replacing with an execute
resource as 我能够通过替换为execute
资源来使其工作
execute "install gem" do
command "gem install bundler --no-rdoc --no-ri"
end
and remove 并删除
gem_package 'bundler' do
options '--no-ri --no-rdoc'
# gem_binary "/usr/local/ruby/2.1.2/bin/gem"
end
I am sorry this is not really a direct answer to my original question, but I solved the problem another way and wanted to share it with you. 抱歉,这并不是我最初提出的问题的直接答案,但是我以另一种方式解决了该问题,并希望与您分享。
I found the website rove.io and chose Languages > Ruby > rbenv > 2.1.2, downloaded the package. 我找到了网站rove.io并选择Languages> Ruby> rbenv> 2.1.2,下载了该软件包。 Then I added the bundler gem to the chef.json config in the downloaded Vagrantfile: 然后,将捆绑包gem添加到下载的Vagrantfile中的Chef.json配置中:
chef.json = {
:rbenv => {
:user_installs => [
{
:user => "vagrant",
:rubies => [
"2.0.0-p647"
],
:global => "2.0.0-p647",
'gems' => {
'2.0.0-p647' => [
{
'name' => 'bundler',
'version' => '1.10'
}
]
}
}
]
}
}
Then I created the vagrant machine and everything just worked as it should . 然后,我创建了无业游民的机器, 一切都按预期进行了工作 。
Note: I already tried using rvm and chef before with ubuntu 14. That did not work (due to some strange errors). 注意:之前我已经在ubuntu 14上尝试过使用rvm和Chef。这没有用(由于一些奇怪的错误)。 But the ubuntu version used by the rove.io Vagrantfile works. 但是rove.io Vagrantfile使用的ubuntu版本有效。
i will not specify the cookbook implementation itself, though what you will need to achieve is the following: 尽管您需要实现以下内容,但我不会指定菜谱实现本身:
ruby
version (including gem
). 安装您喜欢的ruby
版本(包括gem
)。 ruby
and gem
symlinks, see: /usr/bin/ruby
and /usr/bin/gem
. 更新默认的ruby
和gem
符号链接,请参见: /usr/bin/ruby
和/usr/bin/gem
。 bundler
version. 安装您喜欢的bundler
版本。 you can achieve what you want by implementing minitests
(see minitest , and chef-minitest-handler ) 您可以通过实施minitests
来实现minitests
(请参阅minitest和Chef-minitest-handler )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.