I have a Red Hat Enterprise Linux Server release 6.7 node that I have bootstrapped with CHEF. I've successfully executed multiple cookbooks/recipes on this node. Now I need to setup this node to run Ruby On Rails applications.
I have a cookbook with recipes that successfully ::
installs RVM
installs Ruby v2.2
The Problem
After RVM installs Ruby, the CHEF-Client on the bootstrapped node no longer works. Regardless of what Cookbook/Recipe(s) I try to run, I get the following output ::
PS C:\Users\JW031544\workspace\CHEF\chef-repo> knife ssh dh2vrtooldev01 "chef-client -o recipe[MY_COOKBOOK::default]" --manual-list --ssh-user MY_USER --ssh-password "MY_PASS"
dh2vrtooldev01 Ignoring executable-hooks-1.3.2 because its extensions are not built. Try: gem pristine executable-hooks --version 1.3.2
dh2vrtooldev01 Ignoring gem-wrappers-1.2.7 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.2.7
dh2vrtooldev01 Ignoring nokogiri-1.6.8.1 because its extensions are not built. Try: gem pristine nokogiri --version 1.6.8.1
dh2vrtooldev01 /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'addressable' (= 2.4.0) among 45 total gem(s) (Gem::MissingSpecError)
dh2vrtooldev01 Checked in 'GEM_PATH=/usr/local/rvm/gems/ruby-2.2.4:/usr/local/rvm/gems/ruby-2.2.4#global', execute `gem env` for more information
dh2vrtooldev01 from /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:320:in `to_spec'
dh2vrtooldev01 from /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
dh2vrtooldev01 from /usr/bin/chef-client:4:in `<main>'
If I go onto the node and tell RVM to remove that version of Ruby, then the CHEF-Client will begin working again just fine.
The Question
Does anyone have any idea why CHEF-Client suddenly forgets how to run once RVM installs a version of Ruby?
Source Code
(default.rb)
include_recipe 'abl_rails::rvm_install'
include_recipe 'abl_rails::ruby_install'
(rvm_install.rb)
# Install RVM (if it doesn't already exist)
execute 'install_rvm' do
cwd '/root/'
command 'curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -; curl -L get.rvm.io | bash -s stable'
not_if {::File.exists?('/etc/profile.d/rvm.sh')}
end
(ruby_install.rb)
# Install Ruby
bash 'install_ruby' do
cwd '/root/'
code <<-EOH
source /etc/profile.d/rvm.sh;
rvm install #{node['ruby_version']};
EOH
not_if "source /etc/profile.d/rvm.sh; ruby --version | grep #{node['ruby_version']}", :cwd => '/root'
notifies :run, "bash[set_default_rvm_ruby]", :immediately
end
# Set the default Ruby version in RVM
bash "set_default_rvm_ruby" do
cwd '/root'
code <<-EOH
source /etc/profile.d/rvm.sh;
rvm use #{node['ruby_version']} --default;
EOH
action :run
end
rvm overrides the cd internal function with a custom function, and that is causing the error. Try removing rvm and use a different ruby manager such as rbenv.
Check this blog post for other differences between rvm and rbenv : http://jonathan-jackson.net/rvm-and-rbenv
I'll be honest, I had the same issue before (but not with chef), read a bit more about rvm and decided that it was not the right tool for me. I'm sure there must be a way to make rvm play nicely, but I decided it was not worth the effort.
This may be fixed in chef-client 12.17.x so that chef-client correctly breaks out of the RVM environment:
Related Chef bugs:
https://github.com/chef/appbundler/pull/24
https://github.com/chef/chef/issues/5589
If it is still broken after 12.17.x (when ::Gem.clear_paths exists in the /opt/chef/bin/chef-client appbundler binstub) then a new issue should get cut against appbundler.
(As an RVM user, though, I would not recommend using it for running production services, but I find it very nice to use in a dev workstation kind of environment -- but YMMV).
Related
I'm trying to install Ruby on Rails on my openSUSE Tumbleweed machine and running into some problems.
First, I installed rvm:
curl -L get.rvm.io | bash -s stable
Then I used it to install Ruby 2.3.1:
rvm install 2.3.1
rvm use 2.3.1 --default
Then I configured gem to install to my home directory, not /:
$ cat ~/.gemrc
gem: --user-install
Then I used gem to install bundler:
gem install bundler
That's where I ran into problems. The installation seemed to complete fine:
$ gem install bundler
Successfully installed bundler-1.14.6
Parsing documentation for bundler-1.14.6
Done installing documentation for bundler after 3 seconds
1 gem installed
and I can see it on disk:
$ which bundler
/home/<me>/.gem/ruby/2.3.0/bin/bundler
$ > ls ~/.gem/ruby/2.3.0/gems/bundler-1.14.6/
bin CODE_OF_CONDUCT.md exe LICENSE.md README.md
bundler.gemspec CONTRIBUTING.md ISSUES.md man
CHANGELOG.md DEVELOPMENT.md lib Rakefile
But it doesn't actually run, giving a really weird error message:
$ bundler -v
/home/<me>/.rvm/rubies/ruby-2.3.1/lib64/ruby/site_ruby/2.3.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
from /home/<me>/.rvm/rubies/ruby-2.3.1/lib64/ruby/site_ruby/2.3.0/rubygems.rb:298:in `activate_bin_path'
from /home/<me>/.gem/ruby/2.3.0/bin/bundler:22:in `<main>'
And sure enough, gem list doesn't see it:
$ gem list | grep -i bundler | wc -l
0
I get a similar problem when trying to run rails; it complains that it can't find railties, even though it is clearly installed on disk in ~/.gem/ruby/2.3.0/gems, and gem list doesn't show it.
What's going on here?
First select rvm source by command:
source ~/.rvm/scripts/rvm
and then try.
TL;DR how can I install a Ruby gem on Travis for a non-ruby (mostly Python) project, such that I can use the executable that gem provides as part of the build system.
I'm trying to install a Ruby gem for use in building some extra stuff in my python project, post-testing and before deployment. Specifically, I want to use github-changelog-generator to auto generate the changelog for me.
It seems I can't install to root, because the new containerised builds on Travis don't allow sudo.
I've tried installing using gem install --user-install github_changelog_generator. Initially, just that gave a command not found error when running github_changelog_generator.
Trying export PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH" prior to running github_changelog_generator results in the following:
/home/travis/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:315:in `to_specs': Could not find 'github_changelog_generator' (>= 0) among 14 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/home/travis/.rvm/gems/ruby-1.9.3-p551:/home/travis/.rvm/gems/ruby-1.9.3-p551#global', execute `gem env` for more information
from /home/travis/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:324:in `to_spec'
from /home/travis/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:64:in `gem'
from /home/travis/.gem/ruby/1.9.1/bin/github_changelog_generator:22:in `<main>'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `eval'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `<main>'
which would suggest to me it has sort of found it but doesn't quite understand something.
I've no doubt this is obvious to someone with more Ruby experience than I have.
The current travis yaml snippet is as follows:
after_success:
- gem install --user-install github_changelog_generator
- export PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
- github_changelog_generator -u pyFFTW -p pyFFTW
UPDATE:
I didn't realize RVM wasn't initialized on Python projects, so the fix is to let RVM setup the environment, e.g. by installing a version of Ruby (instead of default 1.9.3 in the container):
before_install:
- rvm get stable --auto-dotfiles
- rvm install 2.3.1
or, if you want the default version of RVM Ruby:
before_install:
- rvm default
or, if you want to only install RVM if the build is successful (e.g. you expect Travis failures more often than not):
after_success:
- rvm default
RVM will setup GEM_HOME and GEM_PATH for you, so that commands like gem and bundler will use the correct Ruby and paths.
(Previous answer follows - still useful for debugging)
If you're installing gems, PATH is not the only important variable to locate and load a gem. You also need to properly set GEM_HOME and GEM_PATH.
If in doubt, before the gem install run gem env, which will show you the whole current gem environment (where gems are installed, what the PATH is, etc.). You can also run gem list to verify that the gem is properly installed and available. gem contents github_changelog_generator will show you exactly where the files were installed.
If you paste the output, it will become obvious what needs to change.
Travis also uses bundler for loading gems, so if you have a Gemfile and that gem isn't in the Gemfile, it might be ignored in some cases.
Again, out from gem env should give clues on what the Ruby environment looks like on a python project/container.
BTW, what does the rest of the .travis.yml file look like? Do you have a language set? Do you have sudo: false set?
I have previously been running an old version of Ruby, version 1.9.3, because that is what Ubuntu apt-get installs. Sass was installed with gem install sass and things works as planned. However, Sass would always tell me "Please upgrade ruby. < 2.0.0 will soon be not-supported," so I wanted to do that. I ran sudo apt-get purge ruby rubygems libruby and started to go to work.
First, I tried to install is with rvm, and that didn't go too well, so I did my best to remove that, but I may have missed some things, so don't rule that out. As per this guide ruby seems to have been successfully installed. I then ran gem install sass so I can compile some css. The following are some relevant outputs to prove the correct installation:
$ chruby
ruby-2.1.9
* ruby-2.3.1
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ sass -v
Sass 3.4.22 (Selective Steve)
However, when I try to integrate Sass compiling into NetBeans 8.1, the compiler throws this error for every file.
"~/.gem/ruby/2.3.1/bin/sass" "--cache-location" "~/.cache/netbeans/8.1/sass-compiler" "--debug-info" <sass input> <sass output>
~/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'sass' (>= 0.a) among 11 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=~/.gem/ruby/2.3.0:~/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0', execute `gem env` for more information
from ~/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from ~/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from ~/.gem/ruby/2.3.1/bin/sass:22:in `<main>'
Every file comes up with this error.
From reading around, it seems like it might be a path error. But it looks like I have the correct path setup.
$ echo $PATH
~/.gem/ruby/2.3.1/bin:~/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/bin:~/.rubies/ruby-2.3.1/bin:~/bin:~/.gem/ruby/2.3.1/bin:~/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/bin:~/.rubies/ruby-2.3.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ echo $GEM_PATH
~/.gem/ruby/2.3.1:~/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0
I'm willing to try anything at this point.
EDIT: More information on why it might be a path error.
whereis for ruby, gem, and sass all output nothing. dpkg --get-selections | grep ruby outputs nothing. type ruby outputs the path to the .rubies directory, along with type gem and type sass outputs to the .gem directory.
RVM installation instructions
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
source /home/rvm/.rvm/scripts/rvm
rvm install <the ruby version you want e.g. 2.3.1>
Using the command-line gem tool, how can I install a specific version of a gem?
Use the -v flag:
$ gem install fog -v 1.8
Use the --version parameter (shortcut -v):
$ gem install rails -v 0.14.1
…
Successfully installed rails-0.14.1
You can also use version comparators like >= or ~>
$ gem install rails -v '~> 0.14.0'
…
Successfully installed rails-0.14.4
With newer versions of rubygems you can tighten up your requirements:
$ gem install rails -v '~> 0.14.0, < 0.14.4'
…
Successfully installed rails-0.14.3
Since some time now you can also specify versions of multiple gems:
$ gem install rails:0.14.4 rubyzip:'< 1'
…
Successfully installed rails-0.14.4
Successfully installed rubyzip-0.9.9
But this doesn't work for more than one comparator per gem (yet).
For installing
gem install gemname -v versionnumber
For uninstall
gem uninstall gemname -v versionnumber
for Ruby 1.9+ use colon.
gem install sinatra:1.4.4 prawn:0.13.0
As others have noted, in general use the -v flag for the gem install command.
If you're developing a gem locally, after cutting a gem from your gemspec:
$ gem install gemname-version.gem
Assuming version 0.8, it would look like this:
$ gem install gemname-0.8.gem
You can use the -v or --version flag. For example
gem install bitclock -v '< 0.0.2'
To specify upper AND lower version boundaries you can specify the --version flag twice
gem install bitclock -v '>= 0.0.1' -v '< 0.0.2'
or use the syntax (for example)
gem install bitclock -v '>= 0.0.1, < 0.0.2'
The other way to do it is
gem install bitclock:'>= 0.0.1'
but with the last option it is not possible to specify upper and lower bounderies simultaneously.
[gem 3.0.3 and ruby 2.6.6]
Linux
To install different version of ruby, check the latest version of package using apt as below:
$ apt-cache madison ruby
ruby | 1:1.9.3 | http://ftp.uk.debian.org/debian/ wheezy/main amd64 Packages
ruby | 4.5 | http://ftp.uk.debian.org/debian/ squeeze/main amd64 Packages
Then install it:
$ sudo apt-get install ruby=1:1.9.3
To check what's the current version, run:
$ gem --version # Check for the current user.
$ sudo gem --version # Check globally.
If the version is still old, you may try to switch the version to new by using ruby version manager (rvm) by:
rvm 1.9.3
Note: You may prefix it by sudo if rvm was installed globally. Or run /usr/local/rvm/scripts/rvm if your command rvm is not in your global PATH. If rvm installation process failed, see the troubleshooting section.
Troubleshooting:
If you still have the old version, you may try to install rvm (ruby version manager) via:
sudo apt-get install curl # Install curl first
curl -sSL https://get.rvm.io | bash -s stable --ruby # Install only for the user.
#or:# curl -sSL https://get.rvm.io | sudo bash -s stable --ruby # Install globally.
then if installed locally (only for current user), load rvm via:
source /usr/local/rvm/scripts/rvm; rvm 1.9.3
if globally (for all users), then:
sudo bash -c "source /usr/local/rvm/scripts/rvm; rvm 1.9.3"
if you still having problem with the new ruby version, try to install it by rvm via:
source /usr/local/rvm/scripts/rvm && rvm install ruby-1.9.3 # Locally.
sudo bash -c "source /usr/local/rvm/scripts/rvm && rvm install ruby-1.9.3" # Globally.
if you'd like to install some gems globally and you have rvm already installed, you may try:
rvmsudo gem install [gemname]
instead of:
gem install [gemname] # or:
sudo gem install [gemname]
Note: It's prefered to NOT use sudo to work with RVM gems. When you do
sudo you are running commands as root, another user in another shell
and hence all of the setup that RVM has done for you is ignored while
the command runs under sudo (such things as GEM_HOME, etc...). So to
reiterate, as soon as you 'sudo' you are running as the root system
user which will clear out your environment as well as any files it
creates are not able to be modified by your user and will result in
strange things happening.
Prior to installing, you can check the available versions with the list command.
gem list ^[gemname]$ --remote --all
gem install [gemname] -v [version]
I feel like a compelte idiot, but I've been wrking on this all day and getting no where.
I've restarted several times trying to get a full install of Ruby on my OSX environment, RVM, Brew, Ruby: and every time I get through to the Ruby install it bottoms out on the rubygems install.
The reason I'm having to start again is that the RVM wouldn't update in Jewelerybox after my first successfull install (used a packaged all-in-one RubyInstaller) so I couldn't manage my gems - a problem caused by the initial Ruby install on the system living in the /usr/local and not under my own directory. To fix this I uninstalled all my Ruby stuff and started again.
All ok until the ruby compiler started gacking on the rubygems install section when installing ruby 2.0.0. Checking out the OSX system files under usr/bin I see that rubygems isn't there either (it should be present by default on OSX). Any ideas? (note that XCode is up to date and has command line tools installed)
Last attempt was:
$ rvm get head --autolibs=3 # get the latest RVM and build required libs
$ rvm requirements # just in case, install all other required stuff
$ rvm remove 2.0.0
$ rvm install ruby-2.0.0
. . . which fires the following error:
[2013-03-19 23:21:50] /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
Exception `LoadError' at /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rubygems.rb:1073 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rubygems.rb:1082 - cannot load such file -- rubygems/defaults/ruby
mkdir -p /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0
...
install -c -m 0755 /var/folders/nq/wkj89k854tl0w97n68qdn820pzk_51/T/gem.84634 /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/bin/gem
rm /var/folders/nq/wkj89k854tl0w97n68qdn820pzk_51/T/gem.84634
ERROR: While executing gem ... (NoMethodError)
undefined method `fu_stream_blksize' for #<Gem::Commands::SetupCommand:0x007ffd0e054818>
Installing RubyGems
Installing gem executable
I had the exact same error installing ruby v2 within rvm today. I was in a user account on Ubuntu who needed to use 'sudo' -- and enter my account password for sudo -- in order to install OS dependencies.
Your question mentions running rvm requirements to install dependencies. That seems to be new behavior in rvm, as of v1.19. It seemed to install a bunch of dependencies just fine. But then installing ruby bombed.
In earlier rvm versions, typing rvm requirements would just list the dependencies for rvm and for ruby, as in Archonic's answer.
I typed rvm implode and then started over with:
\curl -L https://get.rvm.io | bash -s 1.18.21
source /home/deploy/.rvm/scripts/rvm
rvm requirements
At that point I could install the libraries/tools that rvm said I needed for rvm and ruby, and then rvm install ruby-2.0.0-p0 succeeded.
I believe the issue is where RVM places your dependencies - global vs your user folder. From a book called "Agile development with rails":
First, you’ll need to make sure you have Xcode 3 or later installed...
$ xcodebuild -version
If you have Xcode version 3 installed, you’ll need to install the Git version control system separately. Verify your installation by running the following command:
$ git --version
Next, install RVM itself:
$ curl -L https://get.rvm.io | bash -s stable
Exit your command window or Terminal application and open a new one. This causes your .bash_login to be reloaded. Execute the following command, which provides additional installation instructions tailored to your specific operating system:
$ rvm requirements
Look for the line that tells you how to install the necessary OS dependencies for Ruby (MRI). Once you complete those instructions, you can proceed to install the Ruby interpreter itself:
$ rvm install 2.0.0
The preceding step will take a while as it downloads, configures, and compiles the necessary executables. Once it completes, use that environment, and install rails:
$ rvm use 2.0.0
$ gem install rails --version 4.0.0.beta1 --no-ri --no-rdoc
With the exception of the rvm use statement, each of the above instructions need only be done once. The rvm use statement needs to be repeated each time you open a shell window. The use keyword is optional, so you can abbreviate this to rvm 2.0.0. You can also choose to make it the default Ruby interpreter for new terminal sessions with the following command:
$ rvm --default 2.0.0
You can verify successful installation using the following command:
$ rails -v
If you have trouble, try the suggestions listed under the Troubleshooting Your Install heading on the rvm site.
Hope that does it for you!
This worked for me:
rvm get head
rvm requirements
rvm install ruby-2.0