I am trying to install Compass and Jekyll, but the gem commands fail:
$ gem update
/usr/lib/ruby/1.9.1/psych.rb:154:in `parse': (<unknown>): couldn't parse YAML at line 2 column 0 (Psych::SyntaxError)
From googling, I see that Ruby has updated it's YAML parser and that gems need to update their config/boot.rb file, but that doesn't help me unless I fork every gem that I install.
Here is my .gemrc, it is the only place where I could have screwed something up:
gemhome: /home/dan/.gems
gempath:
- /home/dan/.gems
Ruby version: ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux], installed using apt-get on Ubuntu.
What do I have to do to start installing ruby gems? I know almost nothing about ruby, I just want to install some software that is distributed as gems.
update
Looking at my question, I see that the ruby version in the error message and ruby --version are different. How do the ruby command and the gem command decide which version to use? Does it matter that they are different? update: I now have only ruby 1.9.3. The problem must be with my .gemrc
update
Removing my .gemrc and installing as root works. What is wrong with my .gemrc?
The Yaml syntax is valid. (See http://yamllint.com/).
However, the problem lies in the variables names gemhome and gempath - they are supposed to be GEM_PATH and GEM_HOME.
See What's the difference between GEM_HOME and GEM_PATH? for more info.
You could type in gem env before and after removing the .gemrc file and you should see a difference in the gem path.
The gem configuration file is not really need in your case since your GEM_PATH/ GEM_HOME don't need to be changed from the defaults...
To install gems below your home directory, use the --user-install parameter:
gem install <gem> --user-install
Mentioned in the ruby gem FAQ. A similar question suggest using RVM to manage gems. It installs gems below the home dir.
Related
After installing a Ruby gem system-wide, the binary name of the gem is always appended with a ruby version. Am I doing something wrong?
I'm new to Ruby. So I was checking out some ruby vim plugins and some of them require to install some gems. So I installed the gem system-wide using sudo gem install rubocop for example, but after installation I was not able to execute the rubocop bin in terminal. Instead, I had to run rubocop.ruby2.5. Why is the ruby version always appended? How do I get rid of this? Might be a dumb question but I really appreciate some help. I checked a similar post Ruby gem names with appended ruby version but it didn't help me much. The following is the bin name and location. I'm using openSUSE and Ruby 2.5.3.
~ $ which rubocop.ruby2.5
/usr/bin/rubocop.ruby2.5
Whether or not RubyGems appends the Ruby version number to the executable name is governed by the --[no-]format-executable flag to gem install.
If you don't want the version suffix, you can either use
gem install --no-format-executable <somegem>
Or set this flag in one of your RubyGems configuration files.
My guess is that your Linux distribution has this configuration flag set for globally so that gem executables installed for different Ruby versions don't clobber each other.
Installed Ruby 2.3.1 using rbenv and now I want to enable
gem: --no-document
for all users. I mean I do not want to put it into ~/.gemrc. Here (How to make --no-ri --no-rdoc the default for gem install?) I've read that this global file is /etc/gemrc but it does not work for me.
Tried on Mac with default Ruby 2.0.0, with Ruby installed with rbenv, inside Docker image CentOS 6.7 - no luck, /etc/gemrc does not work for me.
But when I copy gemrc to my home dir with cp /etc/gemrc ~/.gemrc and install any gem, I immediately see that documentation is no longer installed.
Where am I mistaken or maybe something changed in Ruby-world?
The new notation is:
install: --no-document
The directives are now per gem command, not for gem itself.
I'm not a rubyist and there might be something obvious I'm missing.
I've wrote an application in Ruby 1.8.7, I'm trying to package it in Vagrant (running Raring 13.04), but I've to run "bundle install" to install the requirements and even though gem1.8 does exist, running bundle install still install the gems for Ruby 1.9.3. And then my program fails at runtime...
Any idea about how to solve this?
UPDATE 1
The related Gemfile (thanks to the first answerers):
ruby '1.8.7'
# ...
gem 'trollop'
but for ruby1.8 myfile.rb an error is raised
no such file to load -- trollop (LoadError)
After investigation, the problem looks in bundle install:
Your Ruby version is 1.9.3, but your Gemfile specified 1.8.7
I don't get how to solve the problem.
UPDATE 2
After following the advices from #klaffenboeck things have changed. I'm using RVM and have Ruby 1.8.7 when entering in the project folder. Bundler seems to install things correctly, however the require seems to fail... Path problem?
See here for detail about Vagrant / RVM setup: https://rvm.io/integration/vagrant
UPDATE 3
Problem solved, I was missing a:
require 'rubygems'
before all gems (it worked locally but not in Vagrant).
Bundler will install gems (by default) for whichever Ruby is in your PATH.
Try /usr/bin/env ruby -v or which ruby to figure out which one that is; my guess is you're running bundler with Ruby 1.8.
Adding
ruby '1.8.7'
on top of your Gemfile will help diagnose.
Not aware of this problem in general, but try to put the ruby-version at the top of your gemfile:
#Gemfile
ruby '1.8.7'
# followed by your gems
Edit:
this is most likely because your Gemfile.lock states ruby 1.9.3 - run bundle update
Try running gem uninstall bundler, then gem1.8 install bundler.
Your bundle command seems to be running under Ruby 1.9.3. You can verify which ruby executable bundler is using with head -n 1 $(which bundle). You want it to be ruby1.8.
There are a lot of answers for this question that work under older versions of rubygems, but what is the recommended procedure for Rubygems 1.8.x? I have an /etc/gemrc file that looks like this:
gem: --no-rdoc --no-ri
These options seem to be ignored during any gem install.
Update:
After doing some more digging, it seems the problem is related to rvm which partitions not just the various versions of ruby, but their associated configuration files, too. To check where the config file should go, use irb:
require 'rubygems'
Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
# => "/opt/local/rvm/rubies/ruby-1.9.2-p180/etc/gemrc"
You need to put the following in your ~/.gemrc or /etc/gemrc file
install: --no-rdoc --no-ri
It appears that this is dependent on where Ruby--and by extension gem--is installed in general, not just with RVM. I installed Ruby from source. The default install location when your are building from source is /usr/local/bin, so I installed Ruby there. Naturally this installs gem and all the other tools that come with Ruby in the same directory as well. I had my gemrc under /etc, but it didn't start working until I moved it to /usr/local/etc instead.
I later re-installed Ruby under /usr/bin instead /usr/local/bin and got the same result. It is now looking for gemrc under /usr/etc instead of /usr/local/etc. The gem tool must be looking for a path relative to where it's installed like ../etc when searching for the system-wide gemrc file.
I have the identical file but it's in ~/.gemrc and it works for me on RubyGems 1.8.5. I'm using RVM/Ruby 1.9.2 if that makes any difference.
I'm running Ubuntu 10.04 and originally installed ruby 1.9.1 (from source). I've just decided to try out ruby 1.9.2 and rails 3, and it seemed like a good time to use rvm to deal with the multiple ruby installs and gemsets.
rvm installed and seems to be working, I installed ruby 1.9.2 in rvm and made that my default ruby. However, every time I try to install a gem under ruby 1.9.2 I see this error.
mark#Steve-Austins-Penguin:~$ gem install haml
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/mark/.gem/specs
gem environment returns:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0
- RUBY EXECUTABLE: /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/mark/.rvm/gems/ruby-1.9.2-p0
- /home/mark/.rvm/gems/ruby-1.9.2-p0#global
<snip>
But if the correct installation, ruby and gem paths are showing here why is ruby trying to install gems to /home/mark/.gem? All the variables and paths shown by env look right, and I can't find a .gemrc file anywhere on my system that might contain conflicting path settings.
So I guess my question is what might be causing rubygems to attempt to install to /home/mark/.gems instead of the correct paths set by rvm?
In response to the question below:
mark#Steve-Austins-Penguin:~$ echo $PATH
/home/mark/.rvm/gems/ruby-1.9.2-p0/bin:/home/mark/.rvm/gems/ruby-1.9.2-p0#global/bin:/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin:/home/mark/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
mark#Steve-Austins-Penguin:~$ which gem
/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem
mark#Steve-Austins-Penguin:~$ rvm list
rvm rubies
ruby-1.8.7-p302 [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]
mark#Steve-Austins-Penguin:~$ env
rvm_gemsets_path=/home/mark/.rvm/gemsets
MANPATH=:/home/mark/.rvm/man
rvm_scripts_path=/home/mark/.rvm/scripts
rvm_bin_path=/home/mark/.rvm/bin
GEM_HOME=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_patchsets_path=/home/mark/.rvm/patchsets
SHELL=/bin/bash
IRBRC=/home/mark/.rvm/rubies/ruby-1.9.2-p0/.irbrc
rvm_patches_path=/home/mark/.rvm/patches
MY_RUBY_HOME=/home/mark/.rvm/rubies/ruby-1.9.2-p0
rvm_selfcontained=1
USER=mark
__shell_array_start=0
rvm_gems_cache_path=/home/mark/.rvm/gems/cache
rvm_config_path=/home/mark/.rvm/config
rvm_path=/home/mark/.rvm
USERNAME=mark
rvm_gemset_separator=#
rvm_ruby_args=
rvm_rubies_path=/home/mark/.rvm/rubies
PWD=/home/mark
rvm_hooks_path=/home/mark/.rvm/hooks
rvm_version=1.0.1
rvm_src_path=/home/mark/.rvm/src
HOME=/home/mark
rvm_gems_path=/home/mark/.rvm/gems
rvm_ruby_string=ruby-1.9.2-p0
BUNDLE_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_tmp_path=/home/mark/.rvm/tmp
LOGNAME=mark
GEM_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0:/home/mark/.rvm/gems/ruby-1.9.2-p0#global
rvm_action=list
rvm_log_path=/home/mark/.rvm/log
rvm_interactive=1
RUBY_VERSION=ruby-1.9.2-p0
rvm_archives_path=/home/mark/.rvm/archives
rvm_repo_path=/home/mark/.rvm/repos
_=/usr/bin/env
Note that I've edited down the response from env slightly - simply to keep the size of this post under control - by removing all the entries relating to X, GNOME and SSH.
Following up the backtrace from running gem install -V --backtrace --debug haml (thanks zzzhc) and taking a closer look at the /home/mark/.gem directory I found that there were no gems installed there, just gemspec files and gem source files. In the spirit of experimentation I deleted /home/mark/.gem and re ran the gem install command and suddenly it was working. And that it had recreated /home/mark/.gem containing gemspecs for the gems I'd just installed.
It's clear now that I'd misinterpreted the error message in the original question; rubygems didn't fail while trying to install gems to /home/mark/.gem, it was simply using that directory as a temporary store for the gemspecs of newly downloaded gems about to be installed. Before installing rvm I'd been installing gems onto the system using sudo gem install... which would have created the /home/mark/.gem directory with root permissions. So rubygems run without sudo was unable to access the temp directory to store gemspecs in and was aborting before it could install the gems. Doh!
Another way is type which gem after getting into the ruby version. You will get something like this - /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem. Now just type sudo /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem install gem_name.
Specifying the complete path and adding sudo work fine.
check the first line of /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem and look at http://yehudakatz.com/2010/08/24/a-tale-of-abort-traps-or-always-question-your-assumptions/