osx - Can't install gems with Ruby: “invalid byte sequence in UTF-8”

07
2014-07
  • Cristian

    I'm using Mountain Lion. I've installed Ruby first with RVM, then with rbenv. I can assure it's running the latest one with which ruby, it correctly points to the one installed with rbenv.

    gem won't install any gem, it always throws me the same error (not always in the same file, but the same error with split:

    Users/Macbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:1357:in `split': invalid byte sequence in UTF-8 (ArgumentError)
        from /Users/Macbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:1357:in `find_executable0'
        from /Users/Macbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:1564:in `pkg_config'
        from extconf.rb:15:in `<main>'
    

    I've tried setting these exports in my .profile, without luck:

    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    

    I've also updated bash with brew, and activated it with chsh. iTerm2 is correctly configurated with UTF-8 encoding too.

    I have no idea what else to do now. I have XCode 4.6.3.

  • Answers
  • Cristian

    The problem was solved cleaning up all files related with the setting up of the PATHenvironment variable (.bash_profile, .profile, .bashrc) and then installing rvmagain. Executing an echo $PATHrevealed a strange character which broke bundler's processing of the PATH.


  • Related Question

    ruby - Installing Rake: invalid gem format
  • LordHits

    I installed Ruby on WinXP. Used rubyinstaller-1.8.6-p383-rc1.exe.

    Ran gem install rake

    Get error:

    Error installing rake: invalid gem format for C:/Ruby/lib/ruby/gems/1.8/cache/rake-0.8.7.gem

    I've tried deleting the cache folder but i keep getting the same error. Tried with Ruby 1.9.1 too. Same error. What am i doing wrong?


  • Related Answers
  • Ye Lin Aung
    1. Manually download the Rails gem
    2. Unpack it with gem unpack rails-X.X.X.gem
    3. Search the Rakefile file inside the unpacked dir for lines that start with s.add_dependency
    4. Manually download all the dependencies at rubyforge (each one has its own project)
    5. Install each one with gem install xxx.gem. For Rails 2.0.1 the appropriate order is: activesupport, actionpack, actionmailer, activerecord, actionresource, rake, rails.

    And whenever you have an issue with gem, trying updating it first: gem update --system. That usually solves many problems.