1

When I try run rubyscript via terminal using ruby test.rb command It shows me the following error:

MacBook-Air-K:myapp uzytkownik$ ruby test.rb
/Users/uzytkownik/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- gosu (LoadError)
 from /Users/uzytkownik/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:45:in `require'
 from test.rb:2:in `<main>'
MacBook-Air-K:myapp uzytkownik$

What can be source of the problem? Thank you for advance for your help!

My ruby version is 2.3.1 (the latest I suppose)

The test.rb file contains following code:

require 'gosu'

class GameWindow < Gosu::Window
  def initialize(width=320, height=240, fullscreen=false)
    super
    self.caption = 'Hello'
    @message = Gosu::Image.from_text(
      self, 'Hello, World!', Gosu.default_font_name, 30)
  end

  def draw
    @message.draw(10, 10, 0)
  end
end

window = GameWindow.new
window.show
Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
Miszo97
  • 303
  • 2
  • 11
  • 1
    It can't find "gosu". Also, post the error here, in the question. – Dave Newton Oct 01 '16 at 20:47
  • But how? I've installed gosu using "gem install gosu" command. It occurs in a list as a result of "gem list" command. – Miszo97 Oct 01 '16 at 21:00
  • 1
    @Miszo97 this line in your error message: `'require': cannot load such file -- gosu`tell that gem wasn't install – Oleksandr Holubenko Oct 01 '16 at 21:05
  • 2
    Are you sure you installed the gem to the same ruby version you're currently using? If you used `sudo gem install gosu` then the gem got installed to system ruby, rather than the RVM ruby. – philomory Oct 01 '16 at 21:06
  • @philomory Yeah it worked when I used sudo gem install gosu cammand. Thanks a lot! – Miszo97 Oct 01 '16 at 21:19

3 Answers3

1

You should install gem gosu there are instructions for MacOS and Linux.

If you already look at instruction for MacOS, maybe you missed one of this lines:

Gosu is built on top of the SDL 2 library. I recommend installing Homebrew and then running brew install sdl2.

(Versions of Gosu earlier than 0.10.0 also required brew install libogg libvorbis. Gosu 0.10.0 and later bundle stb_vorbis instead.)

or

rbenv also works. rvm is NOT supported - it sometimes works, but just as often, it installs non-standard compilers that are not compatible with Gosu.

Oleksandr Holubenko
  • 4,310
  • 2
  • 14
  • 28
1

The problem has been solved. The problem was I 've isntalled gosu to wrong version of ruby. Command sudo gem install gosu worked and I was managed to run exe file. Thanks for you all!

Miszo97
  • 303
  • 2
  • 11
  • That's actually exactly the opposite of what I meant to indicate with my comments, but it works. As @Alex points out below, gosu is not supported with Rubies installed via RVM (it can work, indeed, I've had it work before, but it doesn't always work and it's kind-of messy determining when it will work and when it won't) – philomory Oct 01 '16 at 21:25
0

Running your script on my system, it loads fine.

If you are using Ruby Gosu on OSX, you might want to go here:

https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X

For what it is worth, I'm currently using Ubuntu 14 with Ruby 2.3 and using rvm 1.11.3.9 I have downloaded gosu 0.10.8 and successfully gotten a gosu window to load. I had the same problem while starting off with Ruby Gosu and using "bundler" in the project directory took care of the gem dependency. In addition to visiting this website:

https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux

and after entering this in the command line:

user@ubuntu:~/Ruby/gosu_project$ sudo apt-get install build-essential libsdl2-dev libsdl2-ttf-dev libpango1.0-dev libgl1-mesa-dev libfreeimage-dev libopenal-dev libsndfile-dev

user@ubuntu:~/Ruby/gosu_project$ gem install gosu

I also had to invoke:

user@ubuntu:~/Ruby/gosu_project$bundle

http://bundler.io/ - also works with MacOSX...

per: https://github.com/gosu/gosu/wiki/ruby-tutorial

This gosu file:

# basic Gosu: gui test file

require 'gosu'

class TestWindow < Gosu::Window   # <-- inherits from Gosu Window Super class

  def initialize
    super 640, 480, false         # <-- width, height, fullscreen = false
    self.caption = "successful gosu test window"
  end

  def update
  end

  def draw
  end

end


TestWindow.new.show

...loads a 640x480 window

user@ubuntu:~/Ruby/gosu_project$ ruby gosu_test.rb
MmmHmm
  • 3,435
  • 2
  • 27
  • 49