-3

This is the output from $ gem env:

Michels-MacBook-Pro:~ michelfrechette$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.2.3 (2015-08-18 patchlevel 173) [x86_64-darwin15]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.2.0
  - USER INSTALLATION DIRECTORY: /Users/michelfrechette/.gem/ruby/2.2.0
  - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /Users/michelfrechette/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.2.3/etc
  - RUBYGEMS PLATFORMS:
  - ruby
    - x86_64-darwin-15
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.2.0
     - /Users/michelfrechette/.gem/ruby/2.2.0
     - /usr/local/Cellar/ruby/2.2.3/lib/ruby/gems/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Library/Frameworks/Python.framework/Versions/3.5/bin
     - /usr/local/bin
     - /Users/michelfrechette/.rbenv/shims
     - /Users/michelfrechette/.rbenv/bin
     - /usr/local/bin
     - /usr/local/sbin
     - /usr/local/mysql/bin
     - /usr/bin
     - /usr/local/heroku/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Users/michelfrechette/.RVM/bin
     - /Applications/Postgres.app/Contents/Versions/9.4/bin
Michels-MacBook-Pro:~ michelfrechette$ 

I am running a script using $ ruby game.rb, which contains:

require 'rubygame'

class Game
end

I am using rbenv to manage my versions of Ruby and it is currently set to 2.3.0-dev; once upon a time I had RVM installed on my MacBook-Pro.

When I run commands like brew update or gem update all appears to be fine.

I've tried using ruby 2.2.0, but it doesn't make a difference.

When I run ruby -v I get 2.3.0p173.

Is this occurring because I once used RVM as my version manager.

Is this the output I should be seeing when I run my file?

Last login: Tue Jan 26 16:27:35 on ttys005
Michels-MacBook-Pro:~ michelfrechette$ ruby game.rb
/usr/local/lib/ruby/gems/2.2.0/gems/nice-ffi-0.4/lib/nice-ffi/library.rb:98:in `load_library': Could not load SDL. (LoadError)
from /usr/local/lib/ruby/gems/2.2.0/gems/ruby-sdl-ffi-0.4/lib/ruby-sdl-ffi/sdl.rb:51:in `<module:SDL>'
from /usr/local/lib/ruby/gems/2.2.0/gems/ruby-sdl-ffi-0.4/lib/ruby-sdl-ffi/sdl.rb:34:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:67:in `require'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:67:in `require'
from /usr/local/lib/ruby/gems/2.2.0/gems/rubygame-2.6.4/lib/rubygame/main.rb:22:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:119:in `require'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:119:in `require'
from /usr/local/lib/ruby/gems/2.2.0/gems/rubygame-2.6.4/lib/rubygame.rb:44:in `block in <top (required)>'
from /usr/local/lib/ruby/gems/2.2.0/gems/rubygame-2.6.4/lib/rubygame.rb:43:in `each'
from /usr/local/lib/ruby/gems/2.2.0/gems/rubygame-2.6.4/lib/rubygame.rb:43:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:126:in `require'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from game.rb:2:in `<main>'
  Michels-MacBook-Pro:~ michelfrechette$

How can I fix this?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Michel Frechette
  • 197
  • 1
  • 2
  • 8
  • We don't have enough information to diagnose the problem without guessing. Your Ruby is one not installed by rvm or rbenv; I could have been installed by Homebrew. Run `gem env` at the command-line and copy/paste the information into your question, formatting it appropriately. I suspect you haven't initialized rbenv correctly. Please review the rbenv documentation and the related links on the right side of this page. Also read "[ask]" and come up with a more indicative title for your question. The more effort you put into the question the better we can help you. – the Tin Man Jan 27 '16 at 02:11
  • Thank you. I have edited my question to better reflect my problem. – Michel Frechette Jan 27 '16 at 19:02

3 Answers3

1

I think you have to learn how to use rbenv: Choosing the Ruby Version

Choosing the Ruby Version

When you execute a shim, rbenv determines which Ruby version to use by reading it from the following sources, in this order:

  1. The RBENV_VERSION environment variable, if specified. You can use the rbenv shell command to set this environment variable in your current shell session.

  2. The first .ruby-version file found by searching the directory of the script you are executing and each of its parent directories until reaching the root of your filesystem.

  3. The first .ruby-version file found by searching the current working directory and each of its parent directories until reaching the root of your filesystem. You can modify the .ruby-version file in the current working directory with the rbenv local command.

  4. The global ~/.rbenv/version file. You can modify this file using the rbenv global command. If the global version file is not present, rbenv assumes you want to use the "system" Ruby—i.e. whatever version would be run if rbenv weren't in your path.

You can use the rbenv command to display the options and to query the status of your current environment. Check it out, it is self explaining I'd say.

Ely
  • 10,860
  • 4
  • 43
  • 64
1

Take a look at your PATH as displayed by gem env:

 - /Library/Frameworks/Python.framework/Versions/3.5/bin
 - /usr/local/bin
 - /Users/michelfrechette/.rbenv/shims
 - /Users/michelfrechette/.rbenv/bin
 - /usr/local/bin
 - /usr/local/sbin
 - /usr/local/mysql/bin
 - /usr/bin
 - /usr/local/heroku/bin
 - /usr/local/bin
 - /usr/bin
 - /bin
 - /usr/sbin
 - /sbin
 - /Users/michelfrechette/.rvm/bin
 - /Applications/Postgres.app/Contents/Versions/9.4/bin

You have multiple issues:

  • Multiple definitions for /usr/bin and /usr/local/bin
  • You have a /usr/local/bin before .rbenv/shims or .rbenv/bin

    This will cause ruby, or any command associated with Ruby, to be searched for in /usr/local/bin before any Ruby managed by rbenv. And, if it's found that will be executed, even if you want rbenv to use a different version.

  • You have a remaining .rvm/bin in your home directory that could be searched if a hit didn't occur in any previous directory, possibly resulting in crashing code since nothing else it points to appears to exist any more.

To fix this:

  • Look in your ~/.bashrc and ~/.bash_profile files and figure out where your PATH is being modified and clean it up. There are lots of resources on the internet explaining how PATH should be defined, but in short you want to search in your .rbenv directory before /usr/local/bin and in /usr/local/bin before any /usr/bin.
  • Look in ~/.bashrc and ~/.bash_profile and make sure that rbenv is being initialized correctly. The documentation explains how to do that.
  • Delete the ~/.rvm directory. rbenv and RVM do not make good companions since they're designed to do the same thing only they do it different ways. The ensuing tug-of-war if they both try to manage your Rubies will make you insane.

Programmers have to understand their underlying OS enough to not get it messed up. You need to understand how your shell uses ~/.bashrc and ~/.bash_profile, how it searches PATH and resolves the names of executables, and how rbenv is supposed to be initialized.

There are multiple answers on SO about rbenv initialization so search. You'll find the information.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • Your explanation is clear and I had a feeling that this was the case. I will read, review, and reflect on the available resources and with a little confidence, I should be able to resolve these issues with my development-enviroment. As you might have already guessed I am rather new to coding. Sincerely, thank you. – Michel Frechette Jan 27 '16 at 21:05
  • Work through that information. Programming is part system administration and part coding; We don't normally need to know as much as a dedicated system-administrator (nor do I ever want to) but knowing enough to stay out of trouble, to know what commands make no sense in a given situation, and what you need to know when asking for help can take a while to learn. You should also read http://stackoverflow.com/help/someone-answers. Wait a couple days before selecting answers because it takes a while for good answers to be formulated, but selecting the answer that helped helps everyone. – the Tin Man Jan 27 '16 at 21:12
0

In your question you have:

require 'rubygems'
require 'rubygame'

I don't think you will need the first require, but your problem is that you are requiring the file you're in. Try removing them altogether and running your program i.e.

# No require statements
class Game
end

Your error message says the problem is from line 2, and that is require 'rubygame'.

Dbz
  • 2,721
  • 4
  • 35
  • 53
  • That was a typo in the question I posed here. The closing quotes are intact in my file. Thank you kindly for the response. – Michel Frechette Jan 26 '16 at 22:53
  • Did you try removing the require statements entirely and running your code? – Dbz Jan 26 '16 at 22:54
  • After the required two gems there's not much else other than the class and it works fine without the gems. – Michel Frechette Jan 26 '16 at 23:06
  • Yup. Your problem is that you are requiring yourself, and you can't do that – Dbz Jan 26 '16 at 23:17
  • Dbz, I'm not clear as to what you mean by 'requiring yourself'. Could you expand on that point. Sincerely,Mitch – Michel Frechette Jan 26 '16 at 23:32
  • Dbz, I'm not clear as to what you mean by 'requiring yourself'. Could you expand on that point? What I understand is that I don't require the gems? Is that correct? I am newish and none of this comes easily to me. Sincerely, Mitch – Michel Frechette Jan 26 '16 at 23:39
  • I thought you were requiring 'game.rb', but you're not. The issue is still the rubygame gem. Try 'gem install rubygame'. Let me know if that works – Dbz Jan 26 '16 at 23:42
  • Both appear in my gem list, rubygame (2.6.4) and rubygems-update (2.5.1). I ran the gem install rubygame as you recommended, but if you'll notice they appear to be part of the stack. Any other thoughts? – Michel Frechette Jan 26 '16 at 23:51