0

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?

Dan Ross
  • 3,596
  • 4
  • 31
  • 60
  • Any particular reason why you use ruby-1.8.7? It was retired last June. Maybe try a newer Ruby installed e.g. with RVM or chruby. – svoop Feb 03 '14 at 19:02
  • It must have been previously installed using apt-get. I will uninstall it now that I have installed the ruby1.9.1 package. – Dan Ross Feb 03 '14 at 19:03
  • update re: Yes, it does matter. You can see the paths used with `gem env`, however, it's usually the Linux distro which deals with switching between different Ruby versions installed at the same time. I'm all Gentoo, so can't help you there, but you might want to look for binaries like `ruby18`, `gem18`, `ruby19` and `gem19`. Probably your `ruby` and `gem` binaries are only symlinks. – svoop Feb 03 '14 at 19:07
  • I uninstalled the ruby package, so now ruby1.9.1 is the only ruby package installed. However, `ruby --version` is `ruby 1.9.3p0`. Maybe I should find a PPA to install ruby 1.9.3 from. The symlinks route to ruby seems convoluted: '/usr/bin/ruby -> /etc/alternatives/ruby -> /usr/bin/ruby1.9.1`. I'm going to uninstall all rubies and get 1.9.3 from a PPA. – Dan Ross Feb 03 '14 at 19:16
  • I installed 1.9.3, which has symlinks for 1.9.1, and I still get the same error that I started with. Installing gems as root no longer works. Maybe I should downgrade to the version that uses the old YAML parser. – Dan Ross Feb 03 '14 at 19:25
  • 1
    I removed `.gemrc` again, and that gets me around the problem. `.gemrc` is yaml, maybe there is a syntax error there? – Dan Ross Feb 03 '14 at 19:32

2 Answers2

1

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...

Community
  • 1
  • 1
Ismail Moghul
  • 2,864
  • 2
  • 22
  • 28
  • Using `GEM_HOME` and `GEM_PATH` didn't change the gem installation directory, but the two variables do show up in `gem env`. I see that `/home/dan/.gem` is one of the default gem home paths, so you're right, I shouldn't need a `.gemrc` at all. I am trying to get gems to install under my home directory so that I don't have to be root to manage them, but that's a subject for another question. Is `GEM_HOME` not the right way to change the gem install path? – Dan Ross Feb 03 '14 at 22:15
  • `gem install --user-install` does what I want. No need for a `.gemrc`. – Dan Ross Feb 03 '14 at 22:21
0

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.

Community
  • 1
  • 1
Dan Ross
  • 3,596
  • 4
  • 31
  • 60