I'm trying to run different gems on Raspbian and they won't work. I tried on two gems: Jekyll and Lolcat.
I've installed both gems:
pi#moon ~ $ sudo gem install lolcat
Successfully installed lolcat-42.0.99
1 gem installed
Installing ri documentation for lolcat-42.0.99...
Installing RDoc documentation for lolcat-42.0.99...
pi#moon ~ $ sudo gem install jekyll
Successfully installed jekyll-1.4.3
1 gem installed
Installing ri documentation for jekyll-1.4.3...
Installing RDoc documentation for jekyll-1.4.3...
These are the errors I receive.
pi#moon ~ $ lolcat --help
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find lolcat (>= 0)
amongst [bundler-1.5.3, bundler-unload-1.0.2, executable-hooks-1.3.1, gem-wrappers-1.2.4, rubygems-bundler-1.4.2, rvm-1.11.3.9] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /usr/local/bin/lolcat:22:in `<main>'
pi#moon ~ $ jekyll
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find jekyll (>= 0)
amongst [bundler-1.5.3, bundler-unload-1.0.2, executable-hooks-1.3.1, gem-wrappers-1.2.4, rubygems-bundler-1.4.2, rvm-1.11.3.9] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /usr/local/bin/jekyll:22:in `<main>'
I was advised to re-install ruby using RVM. I did, and when I run rvm list to see my ruby versions, I get the following:
pi#moon ~ $ rvm list
rvm rubies
=> ruby-1.9.1-p431 [ armv6l ]
* ruby-2.1.0 [ armv6l ]
I tried running the gems on both versions (1.9.1 & 2.1.0) but receive the same errors.
Thank you in advance!
Several things were wrong here:
Firstly, the gems had been installed as root, which meant that their codebase (and any shell scripts or binary commands their installation generated) were root's, not the current users. This was the cause of OP's original failure - namely, the executable scripts could not resolve the gems since they were installed under a different user's rvm environment.
Secondly, even had the gems commands been accessible this could have created all sorts of security problems, given that the files belonged to root. Potentially, if these gems had contained badly-behaved code (or malicious code) embedded within them, a privilege escalation attack might have been possible against the system running the ruby process.
Basically, the TL;DR is that you should always install the gems using the credentials of the user who needs to run the ruby process that requires the gems, and this user should never be root or have superuser rights to the system or filesystem.
Related
chef verify shows error that gems dependencies on this path error
C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:310:in `to_specs': Could not find 'test-kitchen' (= 1.15.0) - did find: [test-kitchen-1.17.0] (Gem::MissingSpecVersionError)
GEM_PATH=C:/Users/ravikiran/AppData/Local/chefdk/gem/ruby/2.3.0;C:/opscode/chefdk/embedded/lib/ruby/gems/2.3.0', execute `gem env` for more information
from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:320:in `to_spec'
from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from C:/opscode/chefdk/bin/kitchen:19:in `<main>'
Remove your ~/.chefdk folder, you probably tried to upgrade some gems in-place at some point. Wiping that out should get you back to baseline (if it doesn't, reinstall the ChefDK package too).
how about installing the test-kitchen (= 1.15.0) gem, that it says is missing. See this on how to install a ruby gem. http://guides.rubygems.org/rubygems-basics/
update on how to install gem using the chefdk's ruby: I don't have a chefdk installed in a windows OS, but you should see the ruby installed by the chefdk here PATH_TO_chefdk/embedded/bin/ruby.
So, i just installed a chefdk on my win10 x64 (as its a friday :) )... And then to use the ruby from chefdk. follow this https://docs.chef.io/install_dk.html .. Refer to the "Powershell" section. But in short, just run chef shell-init powershell | Invoke-Expression in the PS console.
now you should be able to install the gem version.
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 ruby project and I installed all gems using 'bundle install'. Gems was installed in ./vendor/bundle. But I use ruby installed by rvm in another directory and when I try to do something (some command) It is looking for gems in rvm directory. How to install all gems in rvm directory?
Edit:
I installed all gems but when I tried to user simple ruby -T I get:
/home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:298:in `to_specs': Could not find 'rake' (>= 0) among 1 total gem(s) (Gem::LoadError)
from /home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:309:in `to_spec'
from /home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:53:in `gem'
from /home/arkency/.rvm/gems/ruby-1.9.3-p545/bin/rake:22:in `<main>'
from /home/arkency/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `eval'
from /home/arkency/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `<main>'
My gem list contain only:
gem list
*** LOCAL GEMS ***
bundler (1.6.2)
By default, bundler installs gems to the system gem store. However, it has an optional configuration setting to install gems into another directory (in your case vendor/bundle). These gems are then only available in the specific bundler context.
You can force bundler to install the gems into the system gem store by running
bundle install --system
thus making them available to your global ruby installation.
This is necessary as bundler remembers certain options (e.g. the path where to install gems to) in the .bundle directory besides your Gemfile.
I installed a ruby version as below
$ rvm install ruby-1.9.3-p448-dev
and when i checked version as below
$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
But when i tried to install travis like below
$ gem install travis
Building native extensions. This could take a while...
ERROR: Error installing travis:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
/home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `initialize': Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `open'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `block in copy_file'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1370:in `open'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1370:in `copy_file'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:477:in `copy_file'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:396:in `block in cp'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1529:in `fu_each_src_dest0'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:395:in `cp'
from extconf.rb:5:in `<main>'
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.3-p448/gems/travis-1.5.2 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.3-p448/gems/travis-1.5.2/completion/gem_make.out
So how to avoid the above native extensions error and install the travis succesfully using gem
Edit
When i tried the command by including sudo as below
sudo gem install travis
I am getting the below message as success
Building native extensions. This could take a while...
Successfully installed travis-1.5.2
1 gem installed
Installing ri documentation for travis-1.5.2...
Installing RDoc documentation for travis-1.5.2...
And now what all i am trying to do is to set up environ variables on travis
and hence i tried the following command
$ travis encrypt -r travis_uname/app_name EMAIL_HOST_KEY=key_value
and getting the below wierd error
/usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find travis (>= 0) amongst [addressable-2.3.5, backports-3.3.3, bundler-1.3.5, bundler-unload-1.0.1, coderay-1.0.9, ethon-0.6.0, faraday-0.8.8, faraday_middleware-0.9.0, ffi-1.9.0, gh-0.11.3, highline-1.6.19, launchy-2.3.0, method_source-0.8.2, mime-types-1.24, multi_json-1.7.9, multipart-post-1.2.0, net-http-persistent-2.9, net-http-pipeline-1.0.1, netrc-0.7.7, pry-0.9.12.2, pusher-client-0.3.1, rake-10.1.0, ruby-hmac-0.4.0, rubygems-bundler-1.2.2, rubygems-update-2.0.7, rvm-1.11.3.8, slop-3.4.6, typhoeus-0.6.4, websocket-1.0.7, websocket-native-1.0.0] (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1208:in `gem'
from /usr/local/bin/travis:18
So finally how to avoid above error and make the above travis command work successfully ?
First of all, set the Ruby version you are using as a default
rvm use --default ruby-1.9.3-p448-dev
and uninstall the gem previously installed with sudo
sudo gem uninstall travis
this makes sure that all your commands are using the same Ruby version and your machine is clean again. Now to your installation problem. This error
Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)
shows you, that the installer tried to access /home/user/.travis but wasn't able to do so due to a lack of user permissions. This means you need to make sure that the folder belongs to you and is writeable
chown -R `whoami` ~/.travis
chmod -R u+wx ~/.travis
Now go ahead and try to re-install:
gem install travis
and everything should be fine.
Installing the -dev packages fixed it for me...
sudo apt-get install ruby-dev
It happens sometimes when you install some gems with sudo and other not.
Ideally you should never sudo for the gem install.
So if you have several gems owned by root and you want to remove the ruby installation and the related gems, run this command:
sudo rvm remove ruby-2.0.0-p353 --gems
rvm remove is the preferred way of removing rubies from rvm. By default, not only will it remove the ruby and it's source files, it will also get rid of aliases, wrappers, environments and any associated binaries - in other words, it cleans up most of the install.
The --gems flag will get rid of all associated gemsets.
The you should reinstall your ruby version with:
rvm install ruby-2.0.0-p353
and bundle install again.
Can anyone help with an odd Ruby Gem problem I'm having - note I've installed many gems in the past and never seen this.
I've downloaded the net-ssh and net-sftp gems using the following commands:
sudo gem install net-ssh
sudo gem install net-sftp
both installed successfully. However when I reference the files within my code I get the following error:
./workers/ffmpeg_worker.rb:6:in `require': no such file to load -- net/ssh (LoadError)
from ./workers/ffmpeg_worker.rb:6
from ./workers/tests/test_ffmpeg_worker.rb:3:in `require'
from ./workers/tests/test_ffmpeg_worker.rb:3
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]
Note when I do:
gem list --local
The gems are listed as such:
net-scp (1.0.2)
net-sftp (2.0.2, 1.1.0)
net-ssh (2.0.15, 1.1.2)
net-ssh-gateway (1.0.1)
Any clues?
When I see this sort of thing, it usually comes down to having more than one Ruby installed on the machine (which means more than one gem location, etc.), and different apps or environments getting confused about which one to load.
Check for that first. If that isn't the answer, do a gem which net/ssh to see where RubyGems thinks the gem is installed -- make sure it isn't the local user's .gems directory or something.
If neither one solves the mystery, stick some debugging code into your worker script and have it output its load path ($:) so you can see where it's looking.